in Operating System edited by
21,507 views
14 votes
14 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 edited by
by
21.5k views

4 Comments

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

11 Answers

10 votes
10 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 - https://www.winemantech.com/blog/avoiding-race-conditions-with-labview-programming/

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)

selected by
by

4 Comments

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

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. 

0
0
BTW ‘mutual exclusion’ is not a problem that we need to solve. We use semaphores not to solve mutual exclusion but to provide mutual exclusion. They should first learn grammar properly because it confuses us too in the exam!! And it’s not a ‘smart’ attempt, it’s a foolish attempt, rather.
0
0
3 votes
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
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. 

3 Comments

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
0

Ok sir, U mean Option C includes Option D ?

0
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
0
0
2 votes
2 votes

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

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

by

2 Comments

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

0
0
0
0
2 votes
2 votes
b)Process Synchronization. We can also use semaphores to solve various synchronization problems.(Galvin)
by