src/concurrent/dotnet/ThreadPool.cs
/// <summary>
/// Submit the given work to be run by a thread in this pool.
/// If an idle thread is available, the work is immediately
/// run.  If no idle threads are available, but the current number
/// of threads is less than max, then launch a new thread to
/// execute the work.  If the current number of threads is at
/// max, then queue the work until a thread becomes available.
/// </summary>
Submit the given work to be run by a thread in this pool.
If an idle thread is available, the work is immediately
run.  If no idle threads are available, but the current number
of threads is less than max, then launch a new thread to
execute the work.  If the current number of threads is at
max, then queue the work until a thread becomes available.
Submit the given work to be run by a thread in this pool . If an idle thread is available the work is immediately run . If no idle threads are available but the current number of threads is less than max then launch a new thread to execute the work . If the current number of threads is at max then queue the work until a thread becomes available .
[MethodImpl(MethodImplOptions.Synchronized)]
    public void submit(Work work)
    {
      LinkedListNode<Worker> node = idle.First;
      if (node != null)
      {
        Worker worker = (Worker)node.Value;
        idle.RemoveFirst();
        worker.run(work);
        return;
      }
      if (workers.Count < max)
      {
        Worker worker = new Worker(this, work);
        Thread thread = new Thread(worker.run);
        thread.Name = "ThreadPool-Worker-" + (counter++);
        worker.thread = thread;
        thread.Start();
        workers[worker] = worker;
        return;
      }
      pending.AddLast(work);
    }
[ MethodImpl ( MethodImplOptions . Synchronized ) ] public void submit ( Work work ) { LinkedListNode < Worker > node = idle . First ; if ( node != null ) { Worker worker = ( Worker ) node . Value ; idle . RemoveFirst ( ) ; worker . run ( work ) ; return ; } if ( workers . Count < max ) { Worker worker = new Worker ( this , work ) ; Thread thread = new Thread ( worker . run ) ; thread . Name = " " + ( counter ++ ) ; worker . thread = thread ; thread . Start ( ) ; workers [ worker ] = worker ; return ; } pending . AddLast ( work ) ; }
Submit the given work to be run by a thread in this pool.
Submit the given work to be run by a thread in this pool .
// if we have an idle thread, use it // if we are below max, then spawn a new thread // queue the runnable until we have an idle thread
work
Work