【发布时间】:2015-10-09 22:32:32
【问题描述】:
我正在尝试在 C++ 中实现 Test 和 Test-and-set。
根据C++ atomic_flag query state 我们无法检查标志状态,所以有什么解决方法
循环会是这样的
std::atomic_flag lock_stream = ATOMIC_FLAG_INIT;
void ttas_lock()
{
while(lock_Stream);
while(lock_stream.test_and_set());
return
}
错误:无法将“((ttas*)this)->ttas::lock_stream”从“std::atomic_flag”转换为“bool” while(lock_stream)
【问题讨论】:
-
你的代码不清楚,要不要把它从false改成true一次,然后返回?
-
if lock=false while循环中断,然后我测试并设置,如果返回false我得到锁,想知道如何检查lock_Stream状态,定义为std::atomic_flag lock_stream = ATOMIC_FLAG_INIT;
-
听起来您只是想使用带有 unique_lock 的互斥锁?
-
是的,正在尝试实现 TTAS en.wikipedia.org/wiki/Test_and_Test-and-set
标签: c++ multithreading synchronization locking