Skip to content

Instantly share code, notes, and snippets.

@MarioLiebisch
Created June 27, 2017 06:51
Show Gist options
  • Save MarioLiebisch/0e780c34e55c62189efa359c1db13592 to your computer and use it in GitHub Desktop.
Save MarioLiebisch/0e780c34e55c62189efa359c1db13592 to your computer and use it in GitHub Desktop.
Quick example of a threading race condition
#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