multithreading - C++ MultiThread Worker based approach -


i looking develop multi-threaded worker based sub-application. going through approaches on various site , tumbled onto wiki page.

https://en.wikipedia.org/wiki/thread_pool_pattern

when implementing pattern, programmer should ensure thread-safety of queue. in java, can synchronize relevant method using synchronized keyword. bind block modified synchronized 1 atomic structure, therefore forcing threads using associated resource wait until there no threads using resource.( hope achievable applying mutex lock in c++) drawback method, synchronization rather expensive. can create object holds list of jobs in queue, singleton.

what want understand how singleton object containing list of jobs me more synchronizing queue. , how different ?

p.s: know few of might question source of content ( wiki here) still , know more it.

thanks in advance.

why want "reinvent wheel" instead of using industry-standard approaches or (which target c++ applications)? both of them based upon work-stealing scheduler scales (much better shared queue) in both directions, enables nested parallelism, , solves composability issues inevitable when inventing own thread pool or using existing ones fixed number of worker threads (like in ).


Comments