Пример #1
0
 public static void Pulse(object monitor, object condition)
 {
     if (monitor == condition)
     {
         Monitor.Pulse(monitor);
         return;
     }
     MonitorUtils.EnterUninterruptible(condition, out var wasInterrupted);
     Monitor.Pulse(condition);
     Monitor.Exit(condition);
     if (wasInterrupted)
     {
         Thread.CurrentThread.Interrupt();
     }
 }
Пример #2
0
 public static bool Wait(object monitor, object condition, int timeoutInMillis)
 {
     if (monitor == condition)
     {
         return(Monitor.Wait(monitor, timeoutInMillis));
     }
     // Wait must be called while inside `monitor`
     Monitor.Enter(condition);
     Monitor.Exit(monitor);
     try
     {
         return(Monitor.Wait(condition, timeoutInMillis));
     }
     finally
     {
         Monitor.Exit(condition);
         MonitorUtils.EnterUninterruptible(monitor, out var wasInterrupted);
         if (wasInterrupted)
         {
             throw new ThreadInterruptedException();
         }
     }
     // Wait returns while inside `monitor`!
 }