Pithikos / C-Thread-Pool

A minimal but powerful thread pool in ANSI C
MIT License
2.06k stars 603 forks source link

use signaling instead of polling in thpool_wait #24

Closed dweymouth closed 8 years ago

dweymouth commented 8 years ago

Removed exponential polling in thpool_wait and replaced it with waiting on a pthreads condition variable. When a thread goes into idle, it signals if num_threads_working becomes 0.

Tested on basic, pause/resume, and wait test cases.

I might in the near future look into cleaning up the job queue synchronization (esp. regarding the bsem) but it would be a bigger refactoring.

Pithikos commented 8 years ago

Thanks for the contribution dweymouth. Took me a while to test it but it seems all fine now.