No synchronization with main thread.
stolk opened this issue · 1 comments
Interesting library, and would use this, but:
It seems to be missing important synchronization functionality.
There is no mechanism provided that will let the main thread go to sleep until a job queue is empty.
A typical use in multi-threaded programming would be:
- kick off N threads to do the work
- wait for work completion (without burning CPU cycles caused by spinning.)
- integrate the results by assembling the pieces computed in worker threads.
Such a mechanism could be provided by pthread_barrier_t but unfortunately, this is not part of POSIX, and is lacking in OSX.
Hi,
you were right and I have been implementing what you stated (which was much much hard btw). You can now use the function wait()
after you added your work to wait for the work to finish. Here is an example.
Also there are the functions thpool_pause()
and thpool_resume()
which will pause and resume the whole threadpool regardless what they are doing. This can be of use if you are having some complex system with many threadpools for example. thpool_wait()
will initially poll with 0 interval for one second. After that the polling will grow exponentially until reaching the max pollling interval (by default 20 seconds). After that it will fall back into very simple polling of 20 seconds, to save as many cycles as possible for the actual work.