edited by
28,973 views
15 15 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

11 Answers

Best answer
11 11 votes

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

2 2 votes

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

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

2 2 votes
b)Process Synchronization. We can also use semaphores to solve various synchronization problems.(Galvin)
2 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.

2 2 votes

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.

Answer:
Position:
Show:

Related questions

32 32 votes
5 answers 5 answers
30.0k
30.0k views
Kathleen asked Sep 12, 2014
30,025 views
At a particular time of computation, the value of a counting semaphore is $7$. Then $20$ $P$ operations and $15$ $V$ operations were completed on this semaphore. The resu...
7 7 votes
2 answers 2 answers
5.6k
5.6k views
go_editor asked Jun 19, 2016
5,621 views
Consider the following program.main() { fork(); fork(); fork(); }How many new processes will be created?8675
49 49 votes
4 answers 4 answers
17.3k
17.3k views
Kathleen asked Sep 29, 2014
17,319 views
Dirty bit for a page in a page tablehelps avoid unnecessary writes on a paging devicehelps maintain LRU informationallows only read on a pageNone of the above
48 48 votes
3 answers 3 answers
49.6k
49.6k views
Kathleen asked Sep 22, 2014
49,596 views
Increasing the RAM of a computer typically improves performance because:Virtual Memory increasesLarger RAMs are fasterFewer page faults occurFewer segmentation faults occ...