InterlockedExchangePointer 是否有裸露的 c++ 11(或 boost)替代品?
Is there bare c++ 11 (or boost) replacement for InterlockedExchangePointer?
寻找 Win32 InterlockedExchangePointer 的便携、简单和优雅的替代品。理想情况下仅使用 C++11,但 boost 也可以。
standard atomic types 有一个原子 exchange
函数。所以微软语
PVOID volatile target;
old_value = InterlockedExchangePointer(&target, new_value);
会变成
std::atomic<T*> target;
old_value = target.exchange(new_value);
寻找 Win32 InterlockedExchangePointer 的便携、简单和优雅的替代品。理想情况下仅使用 C++11,但 boost 也可以。
standard atomic types 有一个原子 exchange
函数。所以微软语
PVOID volatile target;
old_value = InterlockedExchangePointer(&target, new_value);
会变成
std::atomic<T*> target;
old_value = target.exchange(new_value);