Reputation: 31
I know that SEM_UNDO flag undo operations after process terminates but I want to know how to prove it in my program.
Example:
Semaphore A (process 1) has value = 1;
Semaphore A (process 1) wait.
Semaphore A (process 2) is decrementing (WITH FLAG = SEM_UNDO).
Sempahore A (process 1) has value = 0;
Process 2 end.
semaphore a (process 1) has value = 1 ? (undo decrementing)
Upvotes: 1
Views: 4807
Reputation: 1634
i) You will see that process A would get semaphore 1 time and then again wait. (Because the process B exited and set semaphore value again to 1.)
ii) Now, change step 3 and instead of exit immediately, put sleep(some_time)
. In this case you will see that process A is getting semaphore various times continuously, until someone again set the semaphore value other than 0. Because process B does not exit and can not set back to 1.
Upvotes: 3