wanghenshui / cppweeklynews

c++中文周刊
https://wanghenshui.github.io/cppweeklynews/
Creative Commons Zero v1.0 Universal
433 stars 18 forks source link

166 draft #121

Closed wanghenshui closed 1 month ago

wanghenshui commented 1 month ago

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 commented 1 month ago

https://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/

wanghenshui commented 1 month ago

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

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

isnan判定 DCHECK

wanghenshui commented 1 month ago

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3347r0.pdf

wanghenshui commented 1 month ago

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 commented 1 month ago

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/ 反射给普通库带来压倒性序列化速度