We have three threads or more, can we use only two semaphores (binary or counting semaphores)? An idea that popped into my mind is playing with the number of sem_post-s and sem_wait-s. Any ideas, strategies are welcomed.
views:
43answers:
1
+2
A:
A semaphore is used to protect a shared resource. You need as many semaphores as shared resources, this is not linked to how many threads access these resources.
mouviciel
2010-02-23 14:20:38
if you have concurrency between threads and the race condition occurs, one semaphore is not enough. i.e. there are three threads that run several iterations. If I want those three threads to execute in a particular order, say iteration 0 - threadA, threadB, threadC; iteration 1 - threadA, .... multiple semaphores need to be implemented. So far I've found out that there can be two semaphores doing this. however, could it be done with only one?
bsuv
2010-02-24 10:35:34
Why use threads if they are executed sequentially? answer to this question may reveal some hidden resources that you want to protect.
mouviciel
2010-02-24 11:59:35