3

What happens if I posed a work to thread pool and the threads are already working in boost?

I have seen this topic (How to create a thread pool using boost in C++?) which explains how to create a pool.

I also found in this topic (https://stackoverflow.com/a/12267138/7108553)

that if I assigned a job to a pool and all the threads are working then the job is discarded.

My question is, is this the case if I created a pool in a similar way to this (How to create a thread pool using boost in C++?)?
my understanding is that if I assigned a job to a pool and all the threads are already working then this will be handled by the library internally and once a thread finishes then the job is assigned to it .. is this correct?

and if not, is there an efficient way to keep track of free and occupied threads?

Community
  • 1
  • 1
Wanderer
  • 1,065
  • 5
  • 18
  • 40
  • It depends on the design of the thread pool. You would have to read the documentation for the implementation you choose to use. Queuing addition work is the most common approach, but I can see uses for a thread pool that discards when all threads are in use.. – Richard Critten Mar 04 '17 at 20:17
  • Actually I did but it was not clear on that specific point. – Wanderer Mar 04 '17 at 21:06

1 Answers1

2

In both links the answers use ASIO, which post to the io_service which will enqueue the work until there's a free thread to run it.

If work increases beyond the number of available threads you can associate more threads with the IO service. Obviously there's always a point of diminishing returns.

Lucinda Rigetti
  • 427
  • 3
  • 10