Creating a thread pool using boost

后端 未结 2 627
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 04:39

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

相关标签:
2条回答
  • 2020-12-01 05:16

    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.

    0 讨论(0)
  • 2020-12-01 05:30

    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..

    0 讨论(0)
提交回复
热议问题