6 votes 6 votes Let S be a binary semaphore variable, S=0 What will be the value of S when following operations are performed:- 2P, 4V, 5P, 2P, 8V, 3P, 2V ? Operating System operating-system semaphore made-easy-test-series + – Shamim Ahmed asked Jan 13, 2019 • edited Mar 3, 2019 by ajaysoni1924 Shamim Ahmed 1.5k views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply Show 5 previous comments gate_dreams commented Jan 13, 2019 reply Follow Share Answer is 0. initially s=0. Now, 2P makes 2 processes waiting in queue 4V signals will make 2 of them to complete and final value of s=1 now 5P processes one of them will make s=0 and other 4 will wait 2P process further wait making in all 6 processes to wait 8V will make them complete and finally 2V extra signals make s=1 3P, 1p will complete s=0 and 2P will wait 2V will make them to complete and since no extra signal i.e., V so s remains 0 0 votes 0 votes kumar.dilip commented Jan 17, 2019 reply Follow Share 0?? 0 votes 0 votes balchandar reddy san commented Jan 17, 2019 reply Follow Share should be 1 After 2P,4V,5P,2P.8V,3P semaphore will reach it's initial value '0' and 2V will change it to 1 as it is a binary semaphore. 0 votes 0 votes Please log in or register to add a comment.
Best answer 7 votes 7 votes Answer is 0. initially s=0. Now, 2P makes 2 processes waiting in queue 4V signals will make 2 of them to complete and final value of s=1 now 5P processes one of them will make s=0 and other 4 will wait 2P process further wait making in all 6 processes to wait 8V will make them complete and finally 2V extra signals make s=1 3P, 1p will complete s=0 and 2P will wait 2V will make them to complete and since no extra signal i.e., V so s remains 0 gate_dreams answered Jan 13, 2019 • selected Jan 13, 2019 by Shamim Ahmed gate_dreams comment Share Follow See all 2 Comments See all 2 2 Comments reply Satbir commented Jan 20, 2019 reply Follow Share 2V will make them to complete and since no extra signal i.e., V so s remains 0 In this when all signals are completed and it is a signal operation then why s is not becoming 1 (since S is available for use as no process is waiting) ? 0 votes 0 votes AshishB commented Apr 17, 2021 reply Follow Share Because we only had 2V operations and we used those operations for completing the remaining 2 processes. so IF we do one more operation on V then we would get S=1 but our question stops us at 2V operation. 0 votes 0 votes Please log in or register to add a comment.