`bsem_post_all` may not be working as intended
I've noticed a potential issue with the bsem_post_all function. It appears that this function may not be working as intended and is essentially equivalent to bsem_post. Here's my analysis:
https://github.com/Pithikos/C-Thread-Pool/blob/4eb5a69a439f252d2839af16b98d94464883dfa5/thpool.c#L545-L571
1.bsem_post_all only set bsem_p->v = 1 once.
2. Although it uses pthread_cond_broadcast, multiple threads waiting in bsem_wait would check if bsem_p->v is set to 1 before they leave bsem_wait.
3. If a thread leaves bsem_wait successfully, it will set bsem_p->v = 0, preventing other threads from leaving bsem_wait.
As a result, using one bsem_post_all still only releases one thread waiting in bsem_wait. bsem_post_all is functionally equivalent to bsem_post, possibly consuming more resources due to the broadcast.
In thpool_destroy, looping bsem_post should be sufficient and potentially more efficient:
I refactor the project: refactored codes The refactored codes also tried to solve the issue: #88 #59 #20
Find a better realization of C threadpool. sogou workflow thrdpool