/// <summary> /// Acquire reader lock. /// </summary> public void AcquireReaderLock() { lock (this) { while (writing == true || (preferWriter == true && waitingWriters > 0)) { monitor.Wait(); } ++readingReaders; } }
public void MonitorSimpleWaitPulse() { object locker = new object(); bool go = false; bool gotPulse = false; var thread = new Thread(() => { lock (locker) while (!go) { Monitor2.Wait(locker); } gotPulse = true; }); thread.Start(); lock (locker) { go = true; Monitor2.Pulse(locker); } Assert.IsTrue(thread.Join(250)); Assert.IsTrue(gotPulse); }
/// <summary> /// Desencola el primer objeto de la lista, se bloquea hasta que alguien inserte un elemento /// </summary> /// <returns>El primer objeto de la cola, null si está vacía</returns> public Event draw() { monitor.Enter(); while (itemCount == 0) { monitor.Wait(); } Event eventHandler = queue.Dequeue(); itemCount--; monitor.Exit(); return(eventHandler); }
/// <summary> /// Obtiene el primer mensaje en la cola, null si esta vacía /// </summary> /// <returns>el primer mensaje de la cola o null si está vacía</returns> public Message draw() { monitor.Enter(); while (itemCount == 0) { monitor.Wait(); } Message message = queue.Dequeue(); itemCount--; monitor.Exit(); return(message); }
public void Run() { while (!_done) { var timeout = Scheduler.Normalize(_next - _stopwatch.Elapsed); lock (_cancel) { if (Monitor2.Wait(_cancel, timeout)) { return; } } _state = _action(_state); _next += _period; } }
void Consume() { while (true) // Keep consuming until { // told otherwise. Action item; lock (_locker) { while (_itemQ.Count == 0) { Monitor2.Wait(_locker); } item = _itemQ.Dequeue(); } if (item == null) { return; // This signals our exit. } item(); // Execute item. } }
public static bool Wait(Queue <LoadTask> tileLoadQueue, int WaitForTileLoadThreadTimeout, bool p) { wait.Wait(); return(true); }