Inside and Out…

An attempt to understand technology better…

Rotor – SetMaxThreads, SetMinThreads

Posted by Gaurav Khanna on July 22, 2004

Just finished extending Rotor’s ThreadPool class to support SetMaxThreads and SetMinThreads methods – to modify the extent of the threadpool maintained by the Rotor runtime – just like .NET FX 2.0 has it.

Will post the source code soon…meanwhile, here’s my implementation of SetMinThreadsInternal in Win32ThreadPool.cpp:

/************************************************************************/
// Will be used to set the minimum number of threads in the Rotor Threadpool
// Kumar Gaurav Khanna - 22-Jul-2004
BOOL ThreadpoolMgr::SetMinThreads(DWORD MinWorkerThreads, 
                                     DWORD MinIOCompletionThreads)
{

    if (IsInitialized())
    {
        BOOL result = FALSE;

        // 1) cannot have minimum worker thread limit <=0
        // 2) cannot have minimum worker thread limit equal to 
// or greater than the maximum worker thread limit if ((MinWorkerThreads > 0) && (MinWorkerThreads < MaxLimitTotalWorkerThreads)) { if (MinWorkerThreads <= (DWORD) MinLimitTotalWorkerThreads) { MinLimitTotalWorkerThreads = MinWorkerThreads; result = TRUE; } } return result; } if (InterlockedCompareExchange(&Initialization, 1, 0) == 0) { Initialize(); BOOL result = FALSE; if ((MinWorkerThreads > 0) && (MinWorkerThreads < MaxLimitTotalWorkerThreads)) { if (MinWorkerThreads <= (DWORD) MinLimitTotalWorkerThreads) { MinLimitTotalWorkerThreads = MinWorkerThreads; result = TRUE; } } Initialization = -1; return result; } else // someone else is initializing. Too late, return false { return FALSE; } }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: