2 votes 2 votes 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) ? Operating System operating-system semaphore linked-list + – mcjoshi asked Oct 11, 2016 edited Oct 29, 2016 by mcjoshi mcjoshi 1.2k views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply Kapil commented Oct 11, 2016 i edited by Kapil Oct 11, 2016 reply Follow Share 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. 0 votes 0 votes mcjoshi commented Oct 11, 2016 reply Follow Share Answer given is $1$. 0 votes 0 votes mcjoshi commented Oct 13, 2016 reply Follow Share Given Solution : 2 votes 2 votes Kapil commented Oct 13, 2016 reply Follow Share 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. 1 votes 1 votes mcjoshi commented Oct 13, 2016 reply Follow Share 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. 0 votes 0 votes Kapil commented Oct 13, 2016 reply Follow Share 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. 0 votes 0 votes mcjoshi commented Oct 13, 2016 reply Follow Share 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. 0 votes 0 votes Kapil commented Oct 13, 2016 reply Follow Share Not many up operations, if we use mutex then only 1 at a time will take the control. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes 1 Psy Duck answered Oct 16, 2022 Psy Duck comment Share Follow See all 0 reply Please log in or register to add a comment.