Inverse Of Semaphore
-
Hi all, Semaphore give us the following behavior count thread state ---------------------------- 3 -> no wait 2 -> no wait 1 -> no wait 0 -> WAIT However, I am looking for some tool which enable me to do this : count thread state ---------------------------- 3 -> WAIT 2 -> WAIT 1 -> WAIT 0 -> no wait I know that I can achieve my objective with the combination of : while(WaitForSingleObject(semaphore, 0) == WAIT_OBJECT_0) { WaitForSingleObject(event, INFINITE); } When the other instances start, they each increments the semaphore with ReleaseSemaphore(). When they exit, each decrements the semaphore counter and fires the event. The problem with this approach is, the first instance would hang if any of the other instances terminates abnormally. Any better suggestion, which I can achieve my objective by just using a single primitive tool? Thanks
-
Hi all, Semaphore give us the following behavior count thread state ---------------------------- 3 -> no wait 2 -> no wait 1 -> no wait 0 -> WAIT However, I am looking for some tool which enable me to do this : count thread state ---------------------------- 3 -> WAIT 2 -> WAIT 1 -> WAIT 0 -> no wait I know that I can achieve my objective with the combination of : while(WaitForSingleObject(semaphore, 0) == WAIT_OBJECT_0) { WaitForSingleObject(event, INFINITE); } When the other instances start, they each increments the semaphore with ReleaseSemaphore(). When they exit, each decrements the semaphore counter and fires the event. The problem with this approach is, the first instance would hang if any of the other instances terminates abnormally. Any better suggestion, which I can achieve my objective by just using a single primitive tool? Thanks
Jeffrey Richter has written about this here.
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]