Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created November 19, 2017 19:07
Show Gist options
  • Save luisdeol/308818e5be0fee7948a071d51c991885 to your computer and use it in GitHub Desktop.
Save luisdeol/308818e5be0fee7948a071d51c991885 to your computer and use it in GitHub Desktop.
Example of a situation where Volatile can be used.
private static int _theFlag;
private static int _theValue;
public static void TheFirstThread()
{
_theValue = 10;
_theFlag = 1;
}
public static void TheSecondThread()
{
if (_theFlag == 1)
Console.WriteLine(_theValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment