Advertisement
kirilstanoev

race condition

Dec 20th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. namespace RaceCondition
  4. {
  5.     class Program
  6.     {
  7.         private static int counter;
  8.  
  9.         static void Main(string[] args)
  10.         {
  11.             new Thread(PrintStar).Start();
  12.             new Thread(PrintPlus).Start();
  13.  
  14.             Console.WriteLine();
  15.         }
  16.  
  17.         static void PrintStar()
  18.         {
  19.             for (counter = 0; counter < 5; counter++)
  20.             {
  21.                 Console.Write(" *(" + counter + ")\t");
  22.             }
  23.         }
  24.  
  25.         static void PrintPlus()
  26.         {
  27.             for (counter = 0; counter < 5; counter++)
  28.             {
  29.                 Console.Write(" +(" + counter + ")\t");
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement