Created
June 27, 2017 06:51
-
-
Save MarioLiebisch/0e780c34e55c62189efa359c1db13592 to your computer and use it in GitHub Desktop.
Quick example of a threading race condition
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 <SFML/System.hpp> | |
#include <iostream> | |
int main() | |
{ | |
int i = 0; | |
sf::Thread thread([](int *j) { ++*j; }, &i); | |
thread.launch(); | |
std::cout << i; // This output is a race condition; it's either 0 or 1 depending on how fast the extra thread is executed | |
thread.wait(); | |
std::cout << i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment