Created
April 10, 2020 22:01
-
-
Save npetrenko/9cf381a4c793719e1109b9aad423dac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <thread> | |
#include <chrono> | |
#include <atomic> | |
int message = 1; | |
std::atomic<int> sync_dummy{0}; | |
void Write() { | |
message = 0; | |
sync_dummy.fetch_add(0, std::memory_order_relaxed); | |
} | |
int Read() { | |
sync_dummy.fetch_add(0, std::memory_order_relaxed); | |
return message; | |
} | |
int main() { | |
std::thread t{Write}; | |
std::this_thread::sleep_for(std::chrono::seconds(1)); | |
int result = Read(); | |
t.join(); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment