1 votes 1 votes Will it causing deadlock? How do we fixed it? P1: P2: Wait(S); Wait(Q); Wait(Q); Wait(S); ........ ............. Signal(S); Signal(Q); Signal(Q); Signal(S); Operating System operating-system semaphore process-synchronization + – srestha asked Oct 4, 2018 srestha 1.1k views answer comment Share Follow See all 11 Comments See all 11 11 Comments reply Magma commented Oct 4, 2018 reply Follow Share yes , it leads a deadlock how do we fixed ? P1: P2: Wait(S); Wait(S); Wait(Q); Wait(Q); ........ ............. Signal(S); Signal(Q); Signal(Q); Signal(S); 1 votes 1 votes srestha commented Oct 4, 2018 reply Follow Share plz describe more 0 votes 0 votes Magma commented Oct 4, 2018 i edited by Magma Oct 4, 2018 reply Follow Share but if use this P1: P2: Wait(S); Wait(S); Wait(Q); Wait(Q); ........ ............. Signal(S); Signal(Q); Signal(Q); Signal(S); it doesn't lead any deadlock you check it out this condition in same manner srestha mam check 1 votes 1 votes aambazinga commented Oct 4, 2018 reply Follow Share @srestha a more conceptual way to understand it is as... give the lexicographic order to P & Q. say either p=1 & q= 2 or either q=1 & p=2. and we know that no deadlock will be there if we ensure that processes are requesting for resource in lexicographic order, as no circular wait would be there. so there are 2 ways for avoid deadlock here... either swap p's wait or swap q's wait. 0 votes 0 votes Tesla! commented Oct 4, 2018 reply Follow Share It depends 1) If S and Q are binary semaphores and either of one is 0 then there is a deadlock. 2) If S=1 and Q=1 and they are binary semaphores now X1: Wait(S) (First line of process P1) X2: Wait(Q) (First line of process P2) Now consider following sequence of execution X1->X2 or X2->X1 if any one of the sequence is executed then there is a deadlock. Now how to fix it 1) Make S and Q as counting Semaphore and make (S=1 and Q=2 or S=2 and Q=1) 2) If you want to keep S and Q as binary semaphore then swap first 2 line of either process P1 or P2 but not both 0 votes 0 votes srestha commented Oct 4, 2018 reply Follow Share @Magma Then both process can be in CS in same time . So, ME, and progress will be violated and no synchronization will be there @ aambazinga why lexicographic order has no deadlock? @Tesla If counting semaphore then initial value can be 1,2,3 or anything and any number of process can be in CS at the same time. So, no ME, Progress or BW 0 votes 0 votes Magma commented Oct 4, 2018 reply Follow Share Then both process can be in CS in same time . So, ME, and progress will be violated and no synchronization will be there How ??? In which case ?? 0 votes 0 votes Tesla! commented Oct 4, 2018 reply Follow Share Yes in counting semaphore you can have any value but value that I have mentioned is one of the possible solution 0 votes 0 votes MiNiPanda commented Oct 5, 2018 reply Follow Share @Tesla! Is there any problem in Magma's solution? It will be deadlock free right? Please check once. 0 votes 0 votes Tesla! commented Oct 5, 2018 reply Follow Share Magma answer won't have a deadlock its also one of the possible solution. 0 votes 0 votes DAWID15 commented Dec 16, 2021 reply Follow Share yeah there is no problem in @Magma solution. 0 votes 0 votes Please log in or register to add a comment.