Correct Answer - Option 3 : All of the above
Concept:
Semaphores are used to solve the problem of race condition, mutual exclusion, and process synchronization.
A semaphore is a variable that has an integer value upon which two operations are defined wait and signal, which helps in solving the critical section problem.
Hence the correct answer is option 3.
Race Condition:
A section of code where if multiple threads/processes execute it the final outcome is undefined and depends upon the order in which they execute. Thus some sort of mutual exclusion is required to avoid this condition
Mutual exclusion:
A mutual exclusion (mutex) is a program object that prevents simultaneous access to a shared resource.
Process Synchronization:
Process Synchronization means sharing system resources by processes in a such a way that, Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data
Wait operation:
It decrements the semaphore value. If the value becomes negative, then the process executing the wait is blocked.
Pseudocode :
wait(s)
{
while (s <=0)
s= s-1
}
Signal operation:
It increments the semaphore value. If value is not positive, then a process blocked by wait operation is unblocked.
Pseudocode:
signal(s)
{
s= s+1
}