9.1k views

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
| 9.1k views
0
My Answer is option c All Race condition , process synchronization , mutual exclusion
+2
should be c) ... dont know why it is given b)..
0

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

+4
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 :)
0
yes sir u r right; i told as per Test Evaluation point of view.
+1
Actually if one is preparing for GATE he/she shouldn't solve any ISRO questions.

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.

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
+3

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

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

May be , i think it is smart attempt to make people full ..by 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
3. Mutual exclusion
4. Race condition

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

@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.

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

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.

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 wait(wrt);         . . .         writing is performed         . . . signal(wrt); wait(mutex);         readcount := readcount + 1;         if readcount = 1 then wait(wrt); signal(mutex);         . . .         reading is performed         . . . wait(mutex);         readcount := readcount - 1;         if readcount = 0 then signal(wrt); signal(mutex);

2. Process Synchronization:

See this question: https://gateoverflow.in/964/gate2003-80

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)
0
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 .
0

Ok sir, U mean Option C includes Option D ?

0
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

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

https://en.wikipedia.org/wiki/Semaphore_(programming)

by Active (2.5k points)
0

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

0

Read 2nd answer here which have to know that

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)
+7
By the same argument semaphore usage does not guarantee mutual exclusion.
0
yes, in case of counting semaphore more than 1 process can enter critical section
0

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 .

0

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

http://www.personal.kent.edu/~rmuhamma/OpSystems/Myos/semaphore.htm

0

@tiger

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

http://stackoverflow.com/questions/10898022/differnce-between-counting-and-binary-semaphores

+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)
Semaphore is used to synchronize two or more processes where race around condition arises for a resource
by Active (3.1k points)
+1

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

(hint: mutex is just a binary semaphore)

0
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.
+1
The question simply asks what tasks semaphores are used for. Mutual Exclusion is clearly one such task. Hence, the answer should include III.
0
so finally answer should be C rt?
+1
Yes, I think so..
0
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!!
+1
pragy How can it be C it will also include iv which is none of the above. Isnt it?
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)
+2
yes, I can't imagine why it is not C, but official answer key says B. It should be C.
0
No, B is correct as C also include option IV None of the above, hence C is excluded as a correct option .

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)
0
solutions of race condition --- mutual exclusion and synchronization...

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

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

race condition problem can be avoided by critical section.

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

http://www.personal.kent.edu/~rmuhamma/OpSystems/Myos/intProCom.htm
0

semaphores can avoid synchronization problem