IThreadPoolConfig Interface

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This interface provides methods for configuring a thread pool.

System_CAPS_ICON_important.jpg Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

__interface
    __declspec(uuid("B1F64757-6E88-4fa2-8886-7848B0D7E660")) IThreadPoolConfig : public IUnknown

Methods

GetSizeCall this method to get the number of threads in the pool.
GetTimeoutCall this method to get the maximum time in milliseconds that the thread pool will wait for a thread to shut down.
SetSizeCall this method to set the number of threads in the pool.
SetTimeoutCall this method to set the maximum time in milliseconds that the thread pool will wait for a thread to shut down.

This interface is implemented by CThreadPool.

Header: atlutil.h

Call this method to get the number of threads in the pool.

STDMETHOD(GetSize)(int* pnNumThreads);

Parameters

pnNumThreads
[out] Address of the variable that, on success, receives the number of threads in the pool.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Example

HRESULT DoPoolOperations(IThreadPoolConfig* pPool, int nSize)
{
    int nCurrSize = 0;
    HRESULT hr = pPool->GetSize(&nCurrSize);
    if (SUCCEEDED(hr))
    {
        printf_s("Current pool size: %d\n", nCurrSize);
        hr = pPool->SetSize(nSize);
        if (SUCCEEDED(hr))
        {
            printf_s("New pool size : %d\n", nSize);
            DWORD dwTimeout = 0;
            hr = pPool->GetTimeout(&dwTimeout);
            if (SUCCEEDED(hr))
            {
                printf_s("Current pool timeout: %u\n", dwTimeout);
                // Increase timeout by 10 seconds.
                dwTimeout += 10 * 1000;
                hr = pPool->SetTimeout(dwTimeout);
                if (SUCCEEDED(hr))
                {
                    printf_s("New pool timeout: %u\n", dwTimeout);
                }
                else
                {
                    printf_s("Failed to set pool timeout: 0x%08X\n", hr);
                }
            }
            else
            {
                printf_s("Failed to get pool timeout: 0x%08X\n", hr);
            }
        }
        else
        {
            printf_s("Failed to resize pool: 0x%08X\n", hr);
        }
    }
    else
    {
        printf_s("Failed to get pool size: 0x%08x\n", hr);
    }

    return hr;
}

Call this method to get the maximum time in milliseconds that the thread pool will wait for a thread to shut down.

STDMETHOD(GetTimeout)(DWORD* pdwMaxWait);

Parameters

pdwMaxWait
[out] Address of the variable that, on success, receives the maximum time in milliseconds that the thread pool will wait for a thread to shut down.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Example

See IThreadPoolConfig::GetSize.

Call this method to set the number of threads in the pool.

STDMETHOD(SetSize)(int nNumThreads);

Parameters

nNumThreads
The requested number of threads in the pool.

If nNumThreads is negative, its absolute value will be multiplied by the number of processors in the machine to get the total number of threads.

If nNumThreads is zero, ATLS_DEFAULT_THREADSPERPROC will be multiplied by the number of processors in the machine to get the total number of threads.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Example

See IThreadPoolConfig::GetSize.

Call this method to set the maximum time in milliseconds that the thread pool will wait for a thread to shut down.

STDMETHOD(SetTimeout)(DWORD dwMaxWait);

Parameters

dwMaxWait
The requested maximum time in milliseconds that the thread pool will wait for a thread to shut down.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Example

See IThreadPoolConfig::GetSize.

Classes
CThreadPool Class

Show: