C++ Atomic and memory barrier
implement shared_ptr 1. load acquire store release example Thread 1 ComplicateClass obj = new ComplicateClass(); // call constructor ready.store(true, memory_order_release); Thread 2 while(ready.load(memory_order_acquire) == 0) { this.sleep(); } do_some_stuff(); 2. acq_rel ~smart_ptr() { if (cnt.fetch_sub(1, memory_order_acq_rel) == 0) { delete ptr; } } https://youtu.be/OyNG4qiWnmU