Geeks With Blogs

News
WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Inside and Out... An attempt to understand technology better...
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;
    }

}


Posted on Thursday, July 22, 2004 7:02 PM Rotor | Back to top


Comments on this post: Rotor - SetMaxThreads, SetMinThreads

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Khanna | Powered by: GeeksWithBlogs.net