Sfoglia il codice sorgente

2002-10-24 Gonzalo Paniagua Javier <[email protected]>

	* ThreadPool.cs: now the monitor thread is not sleeping and checking if
	more worker threads needed. It waits on _DataInQueue. If (and only if)
	there's data in the queue it checks if more worker threads needed and
	then sleeps 5 before waiting for queued data again.

svn path=/trunk/mcs/; revision=8500
Gonzalo Paniagua Javier 23 anni fa
parent
commit
8c92294afd

+ 7 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,10 @@
+2002-10-24  Gonzalo Paniagua Javier <[email protected]>
+
+	* ThreadPool.cs: now the monitor thread is not sleeping and checking if
+	more worker threads needed. It waits on _DataInQueue. If (and only if)
+	there's data in the queue it checks if more worker threads needed and
+	then sleeps 5 before waiting for queued data again.
+
 2002-09-28  Gonzalo Paniagua Javier <[email protected]>
 
 	* ThreadPool.cs: set IsThreadPoolThread before starting the worker.

+ 5 - 5
mcs/class/corlib/System.Threading/ThreadPool.cs

@@ -66,7 +66,7 @@ namespace System.Threading
          _ThreadsInUse = 0;
          _ThreadCreateTriggerRequests = 5;
 
-         // Keeps track of requests in the queue and inreases the number of threads if neededs
+         // Keeps track of requests in the queue and increases the number of threads if needed
          _MonitorThread = new Thread(new ThreadStart(MonitorThread));
          _MonitorThread.Start();
       }
@@ -99,8 +99,6 @@ namespace System.Threading
       }
 
       internal void AddItem(ref ThreadPoolWorkItem Item) {
-         CheckIfStartThread();
-         
          if (Interlocked.Increment(ref _RequestInQueue) == 1) {
             _DataInQueue.Set();
          }
@@ -148,9 +146,11 @@ namespace System.Threading
 
       internal void MonitorThread() {
          while (true) {
-            Thread.Sleep(500);
+            if (_DataInQueue.WaitOne ()) {
+		    CheckIfStartThread();
+            }
 
-            CheckIfStartThread();
+            Thread.Sleep(5000);
          }
       }