Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a thread pool using boost

Is it possible to create a thread pool using boost's thread? i was looking all over boost's libs and I couldn't find a thread pool manager (or something like that)... Is there a way to do it?

tnx!

like image 343
grich Avatar asked Nov 03 '10 06:11

grich


2 Answers

I know an answer has been accepted, if you need this right now, and you can't be bothered to write your own thread pool, you could try using boost asio io_service with a concurrency hint (i.e. how many threads it should run) and then post() stuff to this io_service... just an idea..

like image 104
Nim Avatar answered Nov 14 '22 14:11

Nim


There is an unofficial (yet) threadpool in boost. But it's not a problem to implement one yourself especially if great genericity is not a primary goal. Idea: your threadpool can be parametrized with TaskType type and the number of workers. The TP must be given the handler function which takes TaskType. TP contains a queue of added tasks. The real thread function just takes a task from the queue and calls the passed handler. Something like that.

like image 32
Armen Tsirunyan Avatar answered Nov 14 '22 15:11

Armen Tsirunyan