A counting semaphore was initialized to 10. Then 6 P (wait) operations...
Initially we have semaphore value = 10 Now we have to perform 6 p operation means when we perform one p operation it decreases the semaphore values to one. So after performing 6 p operation we get, semaphore values = 10 - 6 = 4 and now we have to perform 4 v operation means when we perform one V operation it increases the semaphore values to one. So after performing 4 v operation we get, semaphore values = 4 + 4 = 8. Option (B) is correct.
View all questions of this test
A counting semaphore was initialized to 10. Then 6 P (wait) operations...
Semaphore Operations
- A semaphore is a synchronization tool used for interprocess communication.
- A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system.
- A semaphore is simply a value in a designated place in operating system (or kernel) storage that each process that uses the semaphore can check and then change.
- Depending on the value that is found, the process can use the resource or will find that it is already in use and must wait for some period before trying again.
P (wait) Operation
- The P (wait) operation decrements (i.e., reduces) the semaphore value by 1.
- If the semaphore value is greater than 0, the P operation will complete immediately and the semaphore value will be decremented.
- If the semaphore value is 0, the P operation will block (i.e., wait) until the semaphore value becomes greater than 0.
V (signal) Operation
- The V (signal) operation increments (i.e., increases) the semaphore value by 1.
- If there are any processes waiting on the semaphore, the V operation will unblock (i.e., wake up) one of the waiting processes.
- If there are no processes waiting on the semaphore, the V operation will simply increment the semaphore value.
Solution
- The counting semaphore was initialized to 10.
- 6 P (wait) operations were completed on this semaphore, which means the semaphore value was decremented by 6.
- The resulting value of the semaphore after the P operations is 10 - 6 = 4.
- 4 V (signal) operations were then completed on this semaphore, which means the semaphore value was incremented by 4.
- The resulting value of the semaphore after the V operations is 4 + 4 = 8.
- Therefore, the correct answer is option B - 8.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).