#include <atomic> #include <stdio.h> #include <thread> std::atomic<int> foo { 0 }; std::atomic<int> bar { 0 }; void set_foo(int x) { foo = x; } void copy_bar() { while (foo == 0) { std::this_thread::yield(); } bar = foo.load(); } void print_bar() { while (bar == 0) { std::this_thread::yield(); } printf("%d\n", bar.load()); } int main(int argc, const char **argv) { std::thread f(print_bar); std::thread s(set_foo, 10); std::thread t(copy_bar); f.join(); s.join(); t.join(); return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15129 | zachwhaley | Add practice directory |