Created
December 22, 2017 10:18
-
-
Save abrhm/eb6ce4549c65a603d6fee9963867b714 to your computer and use it in GitHub Desktop.
Fun with atomics
This file contains 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 <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