[收藏]IOCP Thread Pooling in C#[19]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhengyun_ustc 的 blog

        // shutdown all thread in the pool

        for (int32 ithread = 0; ithread < icurthreadsinpool; ++ithread)

        {

          unsafe

          {

            bool bret = postqueuedcompletionstatus(gethandle, 4, (uint32*) shutdown_iocpthread, null);

          }

        }

 

        // wait here until all the threads are gone

        while (getcurthreadsinpool != 0) thread.sleep(100);

 

        unsafe

        {

          // close the iocp handle

          closehandle(gethandle);

        }

      }

 

      catch

      {

      }

    }

 

the only private method is the iocpfunction method.  this method is spawned as a thread and is made part of the iocp thread pool by calling the getqueuedcompletionstatus win32 api method.  when the getqueuedcompletionstatus win32 api method returns, we check to make sure we are not being asked to shutdown the thread.  the third argument is the data associated with the posted work.  if the data is not shutdown_iocpthread, then real work has been posted into the iocp thread pool and this thread has been chosen to process the work.  the application developer’s supplied user function is called since the application developer is the only one who knows what needs to be done.  once that is complete, the method checks if a new thread should be added to the pool.  this is done by reviewing the number of active threads in the pool.

 

本文关键:[收藏]IOCP Thread Pooling in C#
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top