The Gateway to Computer Science Excellence
+12 votes

Semaphores are used to solve the problem of

  1. Race Condition
  2. Process Synchronization
  3. Mutual Exclusion
  4. None of the above
    1. I and II
    2. II and III
    3. All of the above
    4. None of the above
in Operating System by Active (2.5k points) | 9.1k views
My Answer is option c All Race condition , process synchronization , mutual exclusion
should be c) ... dont know why it is given b)..

@Arjun sir A,B both can be possible. C is not correct here as because it includes IV argument:None of above.  

ISRO questions cannot have correctness to the level of GATE. How you interpret "None of the above" is upto you and how your stars look :)
yes sir u r right; i told as per Test Evaluation point of view.
Actually if one is preparing for GATE he/she shouldn't solve any ISRO questions.

10 Answers

+7 votes
Best answer

This is my view on the above question -

Definitions -

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 the execute. Thus some sort of mutual exclusion is required to avoid this condition

Mutual exculusion - 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

Thus Semaphores are used to solve the problem of Race condition, Mutual exclution, process synchronization.

Ref -

There are few arguments that Semaphore does not gurantee the freedom from race condition. Yes its true as improper use of Semaphore will not gurantee freedom from race condition. However, this argument is invalid as the question never asked which of the following is defintely solved by Semaphore. It is asking Semaphore is used to solve?

Also if the above argument is used then in that case even improper use of Semaphore will not gurantee mutual exclusion.

For example ,

struct semaphore {
Queue L;
int value
} mutex;

up( mutex )
Critical section
up( mutex)

In the above code there is use of semaphore but fails to gurantee mutual exclusion.

The answer to the question could be option C) or B) depending upon what the question setter had in his mind.

If By All of above he meant 1, 2, 3 and not including None of the above the correct option is C) All of above

If really its a tricky question and All of above includes None of above then most appropriate option will be B)

by Active (3.2k points)
selected by

This snap clears all , all 3 are correct but due to wrongly framed question we need to choose option B 

The question setter was drunk :)
@Bikram Sir, I think None of the above got added mistankely.

May be , i think it is smart attempt to make people full putting all of the above intentionally in option C .

Though it is simple question  and semaphores main job is to provide Mutual exclusion to ensure process synchronization, also you can see in this question only option B have ME as a choice ...

That above Galvin snap says clearly that Race condition is the problem and to solve that problem we need to do Mutual exclusion  and Process Synchronization .

Now the funny thing is in this year KV PGT CSE exam they ask this same question :

Semaphores are used to solve the problem of:
1. Process syncronization
2. Belady problem
3. Mutual exclusion
4. Race condition

and KV people provide solution only Mutual Exclusion as the answer . Now people gonna challenge it .

@Bikram Sir, 

Question is really poorly framed .

It says "To solve the problem of" and correct answer given by them is ME and PS. These are not the problems. This is something which is really needed, which is desirable for the correct execution of system to make it progress. Race condition is a problem and deadlock is a problem. 

yes, Race condition is a problem as we can see from the standard book and the solution to that problem is ME and PS .

If really its a tricky question and All of above includes None of above then most appropriate option will be B)

OMG this is what happens when we overthink to make the answer look correct. The question is clearly wrong. 

+3 votes

Answer: C (All of the three)

1. Race Condition:

we enclose any increment or decrement operation with Semaphores, to prevent Race Condition. An example of this can we seen in Readers and Writers Solution.

Writer Reader
        . . .
        writing is performed
        . . .
        readcount := readcount + 1;
        if readcount = 1 then wait(wrt);
        . . .
        reading is performed
        . . .
        readcount := readcount - 1;
        if readcount = 0 then signal(wrt);

2. Process Synchronization:

See this question:

In this question we synchronize process such that 00 always gets printed before 11.

3. Mutual Exclusion:

Obvious one, we can provide ME using semaphores. 

by Boss (17.9k points)
yes al 3 like race, process sync and ME is satisfied but C says All of the above which include IV None of the above hence B is more appropriate

also in final answer key they provide B .

Ok sir, U mean Option C includes Option D ?

No, you did not get my point , just check those options in I , II, III and IV

i am not talking about A, B, C , D ones ..

option IV None of the above is included so if you select C then it is also included hence B is more appropriate
+2 votes

Semaphores are used to solve process synchronization, mutual exclusion and also race condition.

by Active (2.5k points)

What is difference between Process Synchronization and mututal exclusion in simple words ? can you please elaborate ?

+2 votes

Ans should be (b) because with the help of semaphore we can avoid another process to enter into the critical section so , we can achive mutual exclusion through semophores.

2.Race condition: semophores can be used to prevent race condition however, semaphore use is by no means a guarantee.

by Junior (951 points)
By the same argument semaphore usage does not guarantee mutual exclusion.
yes, in case of counting semaphore more than 1 process can enter critical section

This picture clears[ snap from Galvin ] that semaphore is required to solve process Synchronization and Mutual exclusion to prevent from Race condition .

Now option C says all of the above which includes option IV None of the above .

hence B is the only correct answer if we go with the options .


E.W. Dijkstra (1965) abstracted the key notion of mutual exclusion in his concepts of semaphores.



counting semaphores take more than two values, they can have any value you want. The max value that a counting semaphore can take is the the number of processes you want to allow into the critical section at the same time. 

Semaphore's main job is guarantee Mutual exclusion

have a look

+1 vote

It should be option B

Process synchronization and mutual exclusion.

The concept is when one thread is entering into critical section,other thread should wait untill it finishes.So if here proper synchronization is not done,race condition will occur.

Therefore race condition is the result of improper synchronization problem which can be prevented by mutual exclusion and semaphore also.

But  I think race condition is a undesirable situation/hazard/a special condition which may occur inside critical section.So it is  NOT a problem whereas other two are problems.

by Junior (521 points)
0 votes
Semaphore is used to synchronize two or more processes where race around condition arises for a resource
by Active (3.1k points)

Why not Mutual Exclusion? Aren't semaphores used for that?

(hint: mutex is just a binary semaphore)

Mutual Exclusion i.e mutex is generalized form of Semaphore which is a locking mechanism used to sychronize processes exclusively in order to avoid inconsistency.
I think it should not relate to general problem like sychronization of processes.
The question simply asks what tasks semaphores are used for. Mutual Exclusion is clearly one such task. Hence, the answer should include III.
so finally answer should be C rt?
Yes, I think so..
but wrong use of semaphore may leads to mutual exclusion not satisfied and race condition!
so can we say that it is used for process sync!!
pragy How can it be C it will also include iv which is none of the above. Isnt it?
0 votes
Race condition is achieved by making shared data area should not be accessed by two or more processes at the same time which can be achieved using Semaphore. so, answer should be C(all of the above)
by (81 points)
yes, I can't imagine why it is not C, but official answer key says B. It should be C.
No, B is correct as C also include option IV None of the above, hence C is excluded as a correct option .
0 votes

getting rid of Race condition is not the primary purpose of Semaphore.  Semaphore mainly uses to avoid Busy waiting along with M.E. in C.S. to provide Sync.. so (B)

by Active (1.5k points)
solutions of race condition --- mutual exclusion and synchronization...

i.e. to avoid race cond.. we do mutual exclusion and synchronization ...

am i right?
Mainly we avoid Race condition through process synchronization  for this semaphore is used it means even for race condition we can use semaphore na ???
answer B is right..

race condition problem can be avoided by critical section.

let's read this article you will get more clarity .

semaphores can avoid synchronization problem


Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,297 answers
104,978 users