July 2017
Intermediate to advanced
244 pages
6h 33m
English
POCO provides a default thread pool with 16 threads. This number can be changed dynamically. Like with regular threads, a thread pool requires one to pass a Worker class instance which inherits from the Runnable class:
#include "Poco/ThreadPool.h" #include "Poco/Runnable.h" #include <iostream> class HelloRunnable: public Poco::Runnable { virtual void run() { std::cout << "Hello, world!" << std::endl; } }; int main(int argc, char** argv) { HelloRunnable runnable; Poco::ThreadPool::defaultPool().start(runnable); Poco::ThreadPool::defaultPool().joinAll(); return 0; }
The worker instance is added to the thread pool, which runs it. The thread pool cleans up threads which have been idle for a certain time when we add another ...
Read now
Unlock full access