Пример #1
0
        /// <summary>
        /// Tries to acquire and release a mutex.
        /// </summary>
        /// <returns></returns>
        private bool Test1()
        {
            _mutex.Acquire();
            _mutex.Release();

            return(true);
        }
Пример #2
0
 /// <summary>
 /// Picks up a chopstick. Waits if the chopstick is in use by another Philosopher.
 /// Prints messages to the console regarding what the philosopher is doing.
 /// </summary>
 /// <param name="chopstick">The chopstick to pick up</param>
 /// <param name="leftOrRight">Should be set to "left" if the chopstick is
 /// to the left of the philosopher, or "right" if the chopstick is to the
 /// right of the philosopher. Simply used for logging.</param>
 private static void PickUpChopstick(Mutex chopstick, string leftOrRight)
 {
     Console.WriteLine(Thread.CurrentThread.Name + " is picking up his " + leftOrRight + " chopstick");
     chopstick.Acquire();
     Console.WriteLine(Thread.CurrentThread.Name + " has picked up his " + leftOrRight + " chopstick");
 }