Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int x;
- atomic<bool> b(false);
- // thread 1:
- x = 10;
- atomic_thread_fence(memory_order_release);
- b = true;
- // thread 2:
- while(!b){}
- atomic_thread_fence(memory_order_acquire);
- assert(x == 10); // x will always be 10
- int* x = new int;
- atomic<bool> b(false);
- // thread 1:
- *x = 10;
- atomic_thread_fence(memory_order_release);
- b = true;
- // thread 2:
- while(!b){}
- atomic_thread_fence(memory_order_acquire);
- assert(*x == 10); // will *x always be 10?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement