Ejemplo n.º 1
0
 public static RaceCondition RetryCount(this RaceCondition raceCondition, int retryCount, Action action)
 {
     for (int i = 0; i < retryCount; i++)
     {
         action.Invoke();
     }
     return(raceCondition);
 }
Ejemplo n.º 2
0
        public static RaceCondition StartRaceCondition(this RaceCondition raceCondition)
        {
            Thread work1 = new Thread(() => raceCondition.Work1());
            Thread work2 = new Thread(() => raceCondition.Work2());
            Thread work3 = new Thread(() => raceCondition.Work3());

            work1.Start();
            work2.Start();
            work3.Start();

            work1.Join();
            work2.Join();
            work3.Join();

            return(raceCondition);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Race Condition\n");
            RaceCondition raceCondition = new RaceCondition();

            raceCondition.Explanation();

            int retryCount = 3; // retry count for execution RaceCondition

            raceCondition.RetryCount(retryCount, () =>
            {
                raceCondition.StartRaceCondition()
                .ShowResult();
            });

            Console.WriteLine(Environment.NewLine);

            Console.WriteLine("Atomicity\n");
            Atomicity atomicity = new Atomicity();

            atomicity.StartAtomicity()
            .Reset()
            .StartAtomicityWithLockInstance();
        }
Ejemplo n.º 4
0
 public static void ShowResult(this RaceCondition raceCondition)
 {
     Console.WriteLine($"Race condition: Final work = {raceCondition.GetWork}");
 }