Created
November 15, 2017 12:15
-
-
Save jazzpi/4793ec726176a521693a631e97852f17 to your computer and use it in GitHub Desktop.
Can c == c be false?
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 <iostream> | |
#include <thread> | |
// Compile with g++ -std=c++11 a.cpp -pthread | |
volatile int c = 0; | |
volatile bool done = false; | |
void change_c() { | |
while (!done) { | |
c++; | |
} | |
} | |
void check_c() { | |
while (c == c); | |
done = true; | |
} | |
int main() { | |
std::thread t1(change_c); | |
std::thread t2(check_c); | |
t2.join(); | |
t1.join(); | |
std::cout << "Done at c = " << c << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment