Created
November 19, 2017 18:07
-
-
Save luisdeol/831bfec29065d59d8d32fb019c69cd82 to your computer and use it in GitHub Desktop.
Problems when accessing shared data using multithreading programming
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
| 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