CNonStatelessWorker Class

 

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

Receives requests from a thread pool and passes them on to a worker object that is created and destroyed on each request.

System_CAPS_ICON_important.jpg Important

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

template <class Worker>  
class CNonStatelessWorker

Parameters

Worker
A worker thread class conforming to the worker archetype suitable for handling requests queued on CThreadPool.

Public Typedefs

NameDescription
CNonStatelessWorker::RequestTypeImplementation of WorkerArchetype::RequestType.

Public Methods

NameDescription
CNonStatelessWorker::ExecuteImplementation of WorkerArchetype::Execute.
CNonStatelessWorker::InitializeImplementation of WorkerArchetype::Initialize.
CNonStatelessWorker::TerminateImplementation of WorkerArchetype::Terminate.

This class is a simple worker thread for use with CThreadPool. This class doesn't provide any request-handling capabilities of its own. Instead, it instantiates one instance of Worker per request and delegates the implementation of its methods to that instance.

The benefit of this class is that it provides a convenient way to change the state model for existing worker thread classes. CThreadPool will create a single worker for the lifetime of the thread, so if the worker class holds state, it will hold it across multiple requests. By simply wrapping that class in the CNonStatelessWorker template before using it with CThreadPool, the lifetime of the worker and the state it holds is limited to a single request.

Header: atlutil.h

Implementation of WorkerArchetype::Execute.

void Execute(
    Worker::RequestType request,
    void* pvWorkerParam,
    OVERLAPPED* pOverlapped);

Remarks

This method creates an instance of the Worker class on the stack and calls Initialize on that object. If the initialization is successful, this method also calls Execute and Terminate on the same object.

Implementation of WorkerArchetype::Initialize.

BOOL Initialize(void* /* pvParam */) throw();

Return Value

Always returns TRUE.

Remarks

This class does not do any initialization in Initialize.

Implementation of WorkerArchetype::RequestType.

typedef Worker::RequestType RequestType;

Remarks

This class handles the same type of work item as the class used for the Worker template parameter. See CNonStatelessWorker Overview for details.

Implementation of WorkerArchetype::Terminate.

void Terminate(void* /* pvParam */) throw();

Remarks

This class does not do any cleanup in Terminate.

CThreadPool Class
Worker Archetype
Classes

Show: