Пример #1
0
 private static void ReleaseToken()
 {
     if (_barrier.Arrive())
     {
         Console.WriteLine("\n Semaphore Channel Tests Commencing\n");
         Console.WriteLine("**********************************************\n");
     }
     while (!_finishedAcquiring)
     {
         SemaphoreTestRelease();
     }
     if (_barrier.Arrive())
     {
         _finishedAcquiring = false;
         Console.WriteLine("\n Channel Tests Commencing\n");
         Console.WriteLine("**********************************************\n");
     }
     while (!_finishedAcquiring)
     {
         ChannelTestEnqueue();
     }
     if (_barrier.Arrive())
     {
         _testsFinished = true;
     }
 }
Пример #2
0
    private static void ReleaseToken()
    {
        if (_barrier.Arrive())
        {
            Console.WriteLine("\n Semaphore Channel Tests Commencing\n");
            Console.WriteLine("**********************************************\n");
        }
        while (!_finishedAcquiring)
        {
            SemaphoreTestRelease();
        }
        if (_barrier.Arrive())
        {
            _finishedAcquiring = false;
            Console.WriteLine("\n Channel Tests Commencing\n");
            Console.WriteLine("**********************************************\n");
        }
        while (!_finishedAcquiring)
        {
            ChannelTestEnqueue();
        }
        if (_barrier.Arrive())
        {
            _finishedAcquiring = false;
            Console.WriteLine("\n Bounded Channel Tests Commencing\n");
            Console.WriteLine("**********************************************\n");
        }
        while (!_finishedAcquiring)
        {
            BoundedChannelTestEnqueue();
        }
        if (_barrier.Arrive())
        {
            Console.WriteLine("\n More Bounded Channel Tests Commencing\n");
            Console.WriteLine("**********************************************\n");
        }
        int bCTestCount = 0;

        while (bCTestCount < 5)
        {
            BoundedChannelTestEnqueueTimeOuts();
            bCTestCount++;
        }
    }
Пример #3
0
 public void DoCalculations()
 {
     for (int i = _startIdx + 1; i < _finishIdx; i++)
     {
         if (_myMin > _data [i])
         {
             _myMin = _data [i];
         }
     }
     for (int i = _startIdx + 1; i < _finishIdx; i++)
     {
         if (_myMax < _data [i])
         {
             _myMax = _data [i];
         }
     }
     for (int i = _startIdx; i < _finishIdx; i++)
     {
         _mySum += _data [i];
     }
     if (_barrier.Arrive())
     {
         int overallMin = _myMin;
         int overallMax = _myMax;
         int overallSum = 0;
         Console.WriteLine(Thread.CurrentThread.Name + ": Everyone has finished. Time to crunch data.\n");
         foreach (Calculator calc in _calcs)
         {
             if (calc._myMin < overallMin)
             {
                 overallMin = calc._myMin;
             }
             if (calc._myMax > overallMax)
             {
                 overallMin = calc._myMax;
             }
             overallSum += calc._mySum;
         }
         Console.WriteLine(Thread.CurrentThread.Name + ": Min " + overallMin + " - Max " + overallMax + " - Sum " + overallSum + ".\n");
     }
 }