Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created November 19, 2017 18:07
Show Gist options
  • Save luisdeol/831bfec29065d59d8d32fb019c69cd82 to your computer and use it in GitHub Desktop.
Save luisdeol/831bfec29065d59d8d32fb019c69cd82 to your computer and use it in GitHub Desktop.
Problems when accessing shared data using multithreading programming
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
int theAlmightyZero = 0;
Task newAmazingTask = Task.Run(() =>
{
for (int i = 0; i < 1000000; i++)
theAlmightyZero++;
});
for (int j = 0; j < 1000000; j++)
theAlmightyZero--;
newAmazingTask.Wait();
Console.WriteLine("Here it comes a ZERO value! "+theAlmightyZero);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment