Skip to content

Instantly share code, notes, and snippets.

@npetrenko
Created April 10, 2020 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npetrenko/9cf381a4c793719e1109b9aad423dac6 to your computer and use it in GitHub Desktop.
Save npetrenko/9cf381a4c793719e1109b9aad423dac6 to your computer and use it in GitHub Desktop.
#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