(Latest Revision: Sun Apr 2 15:33 PDT 2017 )
program for P0: wait twice on semaphore #0; walk through the doorway. program for P1: open the left half of the door; signal on semaphore #0. program for P2: open the right half of the door; signal on semaphore #0.According to the style of the set-up above, it's kind of like semaphore #0 belongs to P0, and P0 waits on it to figure out when it's OK to perform its action (to walk through the door). On the other hand processes P1 and P2 use P0's semaphore (not their own semaphores) to signal when they are finished with their actions.
program for P0: wait on semaphore #1; wait on semaphore #2; walk through the doorway. program for P1: open the left half of the door; signal on semaphore #1. program for P2: open the right half of the door; signal on semaphore #2.According to this second style, it's kind of like P0 uses semaphores that belong to OTHER PROCESSES to figure out when it's OK to perform P0's action. The other processes use their own semaphores to tell P0 (signal) that they are finished with their actions.
program for P0: wait twice on S0; walk through the doorway. program for P1: wait on S1; open the left half of the door; signal on S0. program for P2: wait on S2; open the right half of the door; signal on S0. program for P3: unlock the door; signal on S1; signal on S2See the consistency? S0 waits on P0 in order to time its action. P1 waits on S1 to time its action. P2 waits on S2 to time its action. The relationship of process #k to semaphore #k is consistent.
program for P0: wait on S1; wait on S2; walk through the doorway. program for P1: wait on S3; open the left half of the door; signal on S1. program for P2: wait on S3; open the right half of the door; signal on S2. program for P3: unlock the door; signal twice on S3.Here the relationship is different, but consistent here too: P1 signals on S1 to indicate that it has finished its action. P2 signals on S2 to indicate that it has finished its action. P3 signals on S3 to indicate that it has finished its action.