共用方式為


IThreadPoolConfig Interface

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at IThreadPoolConfig Interface.

This interface provides methods for configuring a thread pool.

Important

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

Syntax

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

Members

Methods

GetSize Call this method to get the number of threads in the pool.
GetTimeout Call this method to get the maximum time in milliseconds that the thread pool will wait for a thread to shut down.
SetSize Call this method to set the number of threads in the pool.
SetTimeout Call this method to set the maximum time in milliseconds that the thread pool will wait for a thread to shut down.

Remarks

This interface is implemented by CThreadPool.

Requirements

Header: atlutil.h

IThreadPoolConfig::GetSize

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;
}

IThreadPoolConfig::GetTimeout

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.

IThreadPoolConfig::SetSize

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.

IThreadPoolConfig::SetTimeout

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.

See Also

Classes
CThreadPool Class