GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
194 views

Assume that you have a semaphore associated with each item on a doubly linked list. 
Using No other synchronization primitive, What is the fewest number of semaphore that you must acquire for any operation (lookup, insert, delete) ?

asked in Operating System by Veteran (25.3k points)  
edited by | 194 views
Have to tried to consider shared and exclusive locks on a DLL ?

I think 3 semaphores are sufficient as 4 pointers are modified in case of DLL.
Answer given is $1$.

Given Solution :

looks right !

They are not asking to prevent deadlock or starvation. I accounted these for this question as it is not given to do that.
Questions asks for min. semaphores such that given $3$ operations can be performed one at a time. right!
In a doubly linked list we have access to a node from $2$ sides. So, If we go from other side we can perform many together.
This is what i was thinking. suppose we are reading from a node 4 and other thread comes and deletes node 3 then, we have to modify 2 pointers . But that can be done, if question says that there is no possibilty of deadlock and multithreading is there .

Since, it is not concerned about these problems, why not lock the complete list.
When complete list in locked using one semaphore, then it may be the case that all operations are performed from the side that performs UP on semaphore.
Not many up operations, if we use mutex then only 1 at a time will take the control.

Please log in or register to answer this question.



Top Users Sep 2017
  1. Habibkhan

    8796 Points

  2. rishu_darkshadow

    3572 Points

  3. Warrior

    2914 Points

  4. Arjun

    2840 Points

  5. A_i_$_h

    2550 Points

  6. manu00x

    2268 Points

  7. nikunj

    1990 Points

  8. Bikram

    1874 Points

  9. makhdoom ghaya

    1820 Points

  10. SiddharthMahapatra

    1718 Points


26,346 questions
33,928 answers
80,524 comments
31,231 users