Commits

Anonymous committed 020f7d4 Draft

finished Semaphore.Release wakeup improvement

  • Participants
  • Parent commits aad1902

Comments (0)

Files changed (2)

Cineraria.Concurrency/Barrier.cs

 // </copyright>
 // -----------------------------------------------------------------------
 
-// TODO: max 80 cols
 namespace Cineraria.Concurrency
 {
     using System;

Cineraria.Concurrency/Semaphore.cs

             lock (this.SyncRoot)
             {
                 this._tokenCount += tokens;
-                Monitor.PulseAll(this._syncRoot); // TODO: use Pulse (checks: waiting <= tokens (PA), waiting > tokens (P(tokens)), !waiting (noop))
+                if (this._waitingThreads == 0)
+                {
+                    // Do nothing
+                }
+                else if (this._waitingThreads <= tokens)
+                {
+                    Monitor.PulseAll(this.SyncRoot);
+                }
+                else
+                {
+                    for (int i = 0; i < tokens; i++)
+                    {
+                        Monitor.Pulse(this.SyncRoot);
+                    }
+                }
             }
         }