You are here: My Account > Point one > Count three
Headline news
Advertisement
 

Projects / AuxUtils Cpp / Snippets

The project AuxUtils is an auxiliary C++ library that implements the missing functionality from the Boost libraries. The library provides some efficient functions and templates and wraps some platforms dependent functions.
PrevUpHomeNext

Snippet: Thread pool usage

This snippet illustrates how to use thread pool. The simple thread pool concept implementation.

// Creation a thread pool.
// Maximum count of threads in the pool is 10 and initially will be created is 3
auxutils::ept::ThreadPool* poPool = new auxutils::ept::ThreadPool ( 10 , 3 );

// Creation task id
auxutils::ept::ThreadPool::TaskId myTaskId = poPool->createTaskId();

MyClass oMyClass;
// Scheduling the user task function in user class (boost::bind usage)
// All scheduled tasks per task id can't run simultaneously
poPool->schedule (
	myTaskId,
	boost::bind ( &MyClass::myTaskHandler, &oMyClass)
);

// Canceling all scheduled jobs by id
poPool->cancel ( myTaskId );

// Wait for finish scheduled jobs by id
poPool->wait ( myTaskId );

// Delete pool
delete poPool;
PrevUpHomeNext