Commit 9a769384 authored by captainwong's avatar captainwong

testing atomic

parent 88f0a783
...@@ -16,14 +16,12 @@ void test() ...@@ -16,14 +16,12 @@ void test()
thread t1([&x, &y, &r1, &r2]() { thread t1([&x, &y, &r1, &r2]() {
// Thread 1: // Thread 1:
this_thread::sleep_for(0ms);
r1 = y.load(memory_order_relaxed); // A r1 = y.load(memory_order_relaxed); // A
x.store(r1, memory_order_relaxed); // B x.store(r1, memory_order_relaxed); // B
}); });
thread t2([&x, &y, &r1, &r2]() { thread t2([&x, &y, &r1, &r2]() {
// Thread 2: // Thread 2:
this_thread::sleep_for(0ms);
r2 = x.load(memory_order_relaxed); // C r2 = x.load(memory_order_relaxed); // C
y.store(42, memory_order_relaxed); // D y.store(42, memory_order_relaxed); // D
}); });
...@@ -32,7 +30,9 @@ void test() ...@@ -32,7 +30,9 @@ void test()
t2.join(); t2.join();
count++; count++;
printf("\r%zd", count);
if (r1 == 42 && r2 == 42) { if (r1 == 42 && r2 == 42) {
printf("\n");
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment