mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 09:01:19 +03:00
Updated article
This commit is contained in:
@@ -220,7 +220,7 @@ smartThreadPool.QueueWorkItem(System.IO.File.Copy,
|
|||||||
|
|
||||||
<p>I decided to add a new thread every time a new work item is queued and all the threads in the pool are busy. The formula for adding a new thread can be summarized to:</p>
|
<p>I decided to add a new thread every time a new work item is queued and all the threads in the pool are busy. The formula for adding a new thread can be summarized to:</p>
|
||||||
|
|
||||||
<pre lang="text">(InUseThreads + WaitingCallbacks) > WorkerThreads</pre>
|
<pre lang="text">_currentWorkItemsCount > WorkerThreads</pre>
|
||||||
|
|
||||||
<p>where <code>WorkerThreads</code> is the current number of threads in the pool, <code>InUseThreads</code> is the number of threads in the pool that are currently working on a work item, and <code>WaitingCallbacks</code> is the number of waiting work items. (Thanks to <strong>jrshute</strong> for the comment.)</p>
|
<p>where <code>WorkerThreads</code> is the current number of threads in the pool, <code>InUseThreads</code> is the number of threads in the pool that are currently working on a work item, and <code>WaitingCallbacks</code> is the number of waiting work items. (Thanks to <strong>jrshute</strong> for the comment.)</p>
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ smartThreadPool.QueueWorkItem(System.IO.File.Copy,
|
|||||||
|
|
||||||
// If all the threads are busy then try
|
// If all the threads are busy then try
|
||||||
// to create a new one
|
// to create a new one
|
||||||
if ((InUseThreads + WaitingCallbacks) > _workerThreads.Count)
|
if (_currentWorkItemsCount > _workerThreads.Count)
|
||||||
{
|
{
|
||||||
StartThreads(1);
|
StartThreads(1);
|
||||||
}
|
}
|
||||||
@@ -526,9 +526,9 @@ public delegate TResult Func<T1, T2, T3, T4>(T1 arg1,
|
|||||||
|
|
||||||
/// Returns the user-defined object
|
/// Returns the user-defined object
|
||||||
/// that was provided in the QueueWorkItem.
|
/// that was provided in the QueueWorkItem.
|
||||||
/// If the work item callback is Action<...>
|
/// If the work item callback is Action<span class="code-SummaryComment"><...>
|
||||||
/// or Func<...> the State value
|
</span> /// or Func<span class="code-SummaryComment"><...> the State value
|
||||||
/// depends on the WIGStartInfo.FillStateWithArgs.
|
</span> /// depends on the WIGStartInfo.FillStateWithArgs.
|
||||||
object State { get; }
|
object State { get; }
|
||||||
|
|
||||||
/// Cancel the work item execution.
|
/// Cancel the work item execution.
|
||||||
@@ -539,8 +539,8 @@ public delegate TResult Func<T1, T2, T3, T4>(T1 arg1,
|
|||||||
/// the result of the work item is cancelled.
|
/// the result of the work item is cancelled.
|
||||||
/// (See the work item canceling section for more information)
|
/// (See the work item canceling section for more information)
|
||||||
/// Param: abortExecution - When true send an AbortException
|
/// Param: abortExecution - When true send an AbortException
|
||||||
/// to the executing thread.</param>
|
/// to the executing thread.<span class="code-SummaryComment"></param>
|
||||||
/// Returns true if the work item
|
</span> /// Returns true if the work item
|
||||||
/// was not completed, otherwise false.
|
/// was not completed, otherwise false.
|
||||||
bool Cancel(bool abortExecution);
|
bool Cancel(bool abortExecution);
|
||||||
|
|
||||||
@@ -949,7 +949,7 @@ void Print(Printer printer, Document document) {...}
|
|||||||
|
|
||||||
<li><a name="Feature16"><strong>Threads have priority</strong></a>.</li>
|
<li><a name="Feature16"><strong>Threads have priority</strong></a>.</li>
|
||||||
|
|
||||||
<p><code>STPStartInfo</code> contains a property that defines the priority in which the threads are started in the <code>SmartThreadPool</code>. Use it if you know what you are doing. Playing with threads priority may end up with dead locks, live lock, and days locked :-(.</p>
|
<p><code>STPStartInfo</code> contains a property that defines the priority in which the threads are started in the <code>SmartThreadPool</code>. Use it if you know what you are doing. Playing with threads priority may end up with dead locks, live lock, and days locked <img align="top" alt="Frown | :-(" src="http://www.codeproject.com/script/Forums/Images/smiley_frown.gif" /> .</p>
|
||||||
|
|
||||||
<li><a name="Feature17"><strong><code>MaxThreads</code>/<code>MinThreads</code>/<code>Concurrency</code> can be changed at run time</strong></a>.</li>
|
<li><a name="Feature17"><strong><code>MaxThreads</code>/<code>MinThreads</code>/<code>Concurrency</code> can be changed at run time</strong></a>.</li>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user