src/concurrent/dotnet/ThreadPool.cs
/// <summary>
/// A worker thread loops repeatly executing work until it times out.
/// </summary>
A worker thread loops repeatly executing work until it times out.
A worker thread loops repeatly executing work until it times out .
public void run()
      {
        try
        {
          while (true)
          {
            try { work._work(); } catch (System.Exception e) { Fan.Sys.Err.dumpStack(e); }
            work = null;
            lock (this)
            {
              work = pool.ready(this, false);
              if (work != null) continue;
              try { Monitor.Wait(this, pool.idleTime); } catch (ThreadInterruptedException) {}
              if (work != null) continue;
              work = pool.ready(this, true);
              if (work == null) return;
            }
          }
        }
        catch (System.Exception e)
        {
          Fan.Sys.Err.dumpStack(e);
          pool.free(this);
        }
      }
public void run ( ) { try { while ( true ) { try { work . _work ( ) ; } catch ( System . Exception e ) { Fan . Sys . Err . dumpStack ( e ) ; } work = null ; lock ( this ) { work = pool . ready ( this , false ) ; if ( work != null ) continue ; try { Monitor . Wait ( this , pool . idleTime ) ; } catch ( ThreadInterruptedException ) { } if ( work != null ) continue ; work = pool . ready ( this , true ) ; if ( work == null ) return ; } } } catch ( System . Exception e ) { Fan . Sys . Err . dumpStack ( e ) ; pool . free ( this ) ; } }
A worker thread loops repeatly executing work until it times out.
A worker thread loops repeatly executing work until it times out .
// loop processing runnables // execute work // once I am finished this work, I need to // get more work or enter an idle state // let the thread pool know I am idle, if it has pending // work for me, then immediately execute it // idle this thread for a period of time to // see if any new work becomes available // if work was given to me while I was waiting, then do it // check back again for pending work but this time pass true for // idleTimeOver, if still no work for me then it is time to die // if an exception is raised, free worker