【发布时间】:2015-03-24 08:49:26
【问题描述】:
寻找可移植、简单和优雅的 Win32 InterlockedExchangePointer 替代品。理想情况下只使用 C++11,但 boost 也可以。
【问题讨论】:
-
std::atomic 提供交换功能,但仅当您可以将变量的类型更改为
std::atomic<T*>
标签: c++ multithreading winapi c++11 boost
寻找可移植、简单和优雅的 Win32 InterlockedExchangePointer 替代品。理想情况下只使用 C++11,但 boost 也可以。
【问题讨论】:
std::atomic<T*>
标签: c++ multithreading winapi 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);
【讨论】: