std::mutex m;
std::condition_variable cv;
+ std::unique_lock<std::mutex> l(m);
std::atomic<bool> a(false);
std::atomic<bool> b(false);
std::thread t([&]
{
+ {
+ // This ensures we block until cv.wait(l) starts.
+ std::lock_guard<std::mutex> ll(m);
+ }
cv.notify_one();
a.wait(false);
if (a.load())
b.store(true);
}
});
- std::unique_lock<std::mutex> l(m);
cv.wait(l);
std::this_thread::sleep_for(100ms);
a.store(true);
std::mutex m;
std::condition_variable cv;
+ std::unique_lock<std::mutex> l(m);
long aa;
long bb;
std::atomic<long*> a(nullptr);
std::thread t([&]
{
+ {
+ // This ensures we block until cv.wait(l) starts.
+ std::lock_guard<std::mutex> ll(m);
+ }
cv.notify_one();
a.wait(nullptr);
if (a.load() == &aa)
a.store(&bb);
});
- std::unique_lock<std::mutex> l(m);
cv.wait(l);
std::this_thread::sleep_for(100ms);
a.store(&aa);
std::mutex m;
std::condition_variable cv;
+ std::unique_lock<std::mutex> l(m);
std::atomic_flag a;
std::atomic_flag b;
std::thread t([&]
{
+ {
+ // This ensures we block until cv.wait(l) starts.
+ std::lock_guard<std::mutex> ll(m);
+ }
cv.notify_one();
a.wait(false);
b.test_and_set();
b.notify_one();
});
- std::unique_lock<std::mutex> l(m);
cv.wait(l);
std::this_thread::sleep_for(100ms);
a.test_and_set();
std::mutex m;
std::condition_variable cv;
+ std::unique_lock<std::mutex> l(m);
Tp aa = val1;
std::atomic_ref<Tp> a(aa);
std::thread t([&]
{
+ {
+ // This ensures we block until cv.wait(l) starts.
+ std::lock_guard<std::mutex> ll(m);
+ }
cv.notify_one();
a.wait(val1);
if (a.load() != val2)
a = val1;
});
- std::unique_lock<std::mutex> l(m);
cv.wait(l);
std::this_thread::sleep_for(100ms);
a.store(val2);