Skip to content

Instantly share code, notes, and snippets.

@abrhm
Created December 22, 2017 10:18
Show Gist options
  • Save abrhm/eb6ce4549c65a603d6fee9963867b714 to your computer and use it in GitHub Desktop.
Save abrhm/eb6ce4549c65a603d6fee9963867b714 to your computer and use it in GitHub Desktop.
Fun with atomics
#include <atomic>
constexpr uint32_t offset = 10000;
// Called from several thread
void calculate(std::atomic<uint32_t>& number)
{
number *= 2;
// ...... long code
number = number + offset;
}
int main()
{
std::atomic<uint32_t> num = 1;
// Call this function from several thread
calculate(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment