Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

166 draft #121

Closed
wanghenshui opened this issue Aug 15, 2024 · 5 comments
Closed

166 draft #121

wanghenshui opened this issue Aug 15, 2024 · 5 comments

Comments

@wanghenshui
Copy link
Owner

wanghenshui commented Aug 15, 2024

Temporarily dropping a lock: The anti-lock pattern

https://devblogs.microsoft.com/oldnewthing/20240814-00/?p=110129

异步lock暂时解锁的组件。代码

template<typename Mutex>
struct anti_lock
{
    anti_lock() = default;

    explicit anti_lock(Mutex& mutex)
    : m_mutex(std::addressof(mutex)) {
        if (m_mutex) m_mutex->unlock();
    }

private:
    struct anti_lock_deleter {
        void operator()(Mutex* mutex) { mutex->lock(); }
    };

    std::unique_ptr<Mutex, anti_lock_deleter> m_mutex;
};

winrt::fire_and_forget DoSomething()
{
    auto guard = std::lock_guard(m_mutex);

    step1();

    // All co_awaits must be under an anti-lock.
    int cost = [&] {
        auto anti_guard = anti_lock(m_mutex);
        return co_await GetCostAsync();
    }();

    step2(cost);
}
@wanghenshui
Copy link
Owner Author

@wanghenshui
Copy link
Owner Author

Surprisingly Slow NaNs https://voithos.io/articles/surprisingly-slow-nans/

代码存在0除0导致NAN NAN导致性能下降

isnan判定 DCHECK

@wanghenshui
Copy link
Owner Author

@wanghenshui
Copy link
Owner Author

What's so hard about class types as non-type template parameters? https://brevzin.github.io/c++/2024/08/15/cnttp/

NTTP 支持类实例的困难原因 无法判定相等

operator template()

反射影响

@wanghenshui
Copy link
Owner Author

Reflection-based JSON in C++ at Gigabytes per Second https://lemire.me/blog/2024/08/13/reflection-based-json-in-c-at-gigabytes-per-second/
反射给普通库带来压倒性序列化速度

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant