Win32 Threadpool Tutorial Recap


Download source code from MSDN Code Gallery.

This is a quick recap of all the posts in the threadpool series and the methods supported by the wrapper classes.

 

 

Class windowsthreadpool::SimpleThreadPool

Public Member Functions

Description

template<class Function > 
bool  QueueUserWorkItem (Function cb)

Queue a work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItem (Function cb, PVOID State)

Queue a work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

template<class Function > 
bool  QueueUserWorkItemWithLowPri (Function cb)

Queue a low priority work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItemWithHiPri (Function cb)

Queue a high priority work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItemWithLowPri (Function cb, PVOID State)

Queue a low priority work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

template<class Function > 
bool  QueueUserWorkItemWithHiPri (Function cb, PVOID State)

Queue a high priority work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

void  WaitForAll ()

Wait for all queued work items to finish execution.

void  WaitForAllCurrentlyRunning ()

Wait for all running work items to finish execution and cancel any queued work items which haven’t started running.

template<class Function > 
PVOID  RegisterEvent (Function cb, HANDLE Event, int timeout)

Queue a work item to the process-wide threadpool to call Function cb when the event is signaled or the timeout expires.

template<class Function > 
PVOID  RegisterEvent (Function cb, PVOID State, HANDLE Event, int timeout)

Queue a work item to the process-wide threadpool to call Function cb which accepts a PVOID as parameter when the event is signaled or the timeout expires.

template<class Function > 
bool  DestroyEvent (PVOID EventHandle)

Cancel any interest in the event previously registered. Method accepts the handle returned by the RegisterEvent method.

template<class Function > 
bool  ReRegisterEvent (PVOID EventHandle)

ReRegister interest in the event previously registered. Method accepts the handle returned by the RegisterEvent method.

template<class Function > 
bool  ReRegisterEvent (PVOID EventHandle, int timeout)

ReRegister interest in the event previously registered with a different timeout. Method accepts the handle returned by the RegisterEvent method.

 

Class windowsthreadpool::PrivateThreadPool

Public Member Functions

Description

bool  SetThreadpoolMax (size_t max)

Set the maximum number of the threads that can be created in the threadpool.

bool  SetThreadpoolMin (size_t min)

Set the minimum number of the threads to exist in the threadpool.

template<class Function > 
bool  QueueUserWorkItem (Function cb)

Queue a work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItem (Function cb, PVOID State)

Queue a work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

template<class Function > 
bool  QueueUserWorkItemWithLowPri (Function cb)

Queue a low priority work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItemWithHiPri (Function cb)

Queue a high priority work item to the process-wide threadpool to run Function cb.

template<class Function > 
bool  QueueUserWorkItemWithLowPri (Function cb, PVOID State)

Queue a low priority work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

template<class Function > 
bool  QueueUserWorkItemWithHiPri (Function cb, PVOID State)

Queue a high priority work item to the process-wide threadpool to run Function cb which accepts a PVOID as parameter.

void  WaitForAll ()

Wait for all queued work items to finish execution.

void  WaitForAllCurrentlyRunning ()

Wait for all running work items to finish execution and cancel any queued work items which haven’t started running.

template<class Function > 
PVOID  RegisterEvent (Function cb, HANDLE Event, int timeout)

Queue a work item to the process-wide threadpool to call Function cb when the event is signaled or the timeout expires.

template<class Function > 
PVOID  RegisterEvent (Function cb, PVOID State, HANDLE Event, int timeout)

Queue a work item to the process-wide threadpool to call Function cb which accepts a PVOID as parameter when the event is signaled or the timeout expires.

template<class Function > 
bool  DestroyEvent (PVOID EventHandle)

Cancel any interest in the event previously registered. Method accepts the handle returned by the RegisterEvent method.

template<class Function > 
bool  ReRegisterEvent (PVOID EventHandle)

ReRegister interest in the event previously registered. Method accepts the handle returned by the RegisterEvent method.

template<class Function > 
bool  ReRegisterEvent (PVOID EventHandle, int timeout)

ReRegister interest in the event previously registered with a different timeout. Method accepts the handle returned by the RegisterEvent method.

 

Class windowsthreadpool::Timer

Public Member Functions

Description

  Timer (size_t mSeconds, Function cb)

Constructor which accepts a function cb to call when the time expires in milliseconds.

  Timer (size_t mSeconds, size_t Period, Function cb)

Constructor which accepts a function cb to call when the time expires in milliseconds. It keeps calls this function at the specified period in milliseconds.

  Timer (size_t mSeconds, Function cb, PVOID State)

Constructor which accepts a function cb to call and a PVOID parameter which it takes as input when the time expires in milliseconds.

  Timer (size_t mSeconds, size_t Period, Function cb, PVOID State)

Constructor which accepts a function cb to call and a PVOID parameter which it takes as input when the time expires in milliseconds. It keeps calls this function at the specified period in milliseconds.

void  DestroyTimer ()

Cancels all interest in the timer.

Comments (1)

  1. gt227 says:

    Great posts!!

    As you said I would love to see a post about asynchronous IO. Specially using sockets and this new thread pool.

    Thanks,

    G.

Skip to main content