semaphore problem

i have some quastion iam struggling to answer it ..
i have 4 procces
condition :
1)evry process can run by himself
2)procces p1&p3 can run togther in the critical section
and p2,p4 can run togther in the critical section
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
procces 1: 
While(true)
{
semWait(s1);
semWait(s2);
<critical-section>
semSignal(s2);
semSignal(s1);
}

process 2:
While(true)
{
semWait(s2);
semWait(s3);
<critical-section>
semSignal(s3);
semSignal(s2);
}
process 3 :
While(true)
{
semWait(s3);
semWait(s4);
<critical-section>
semSignal(s4);
semSignal(s3);
}
process 4: 
While(true)
{
semWait(s4);
semWait(s1);
<critical-section>
semSignal(s1);
semSignal(s4);
}


now the quastion says that this solution isnt right..and show how the run of this code will not give answer the right conditions
first i thought its a deadlock. and keep thinking but got confused
but then i totaly got confused.
the second quastion show me how with 1 binary semaphore we can solve this conditions
Last edited on
iam sure that is some kind of a dead lock case like
p1 holding s1
and p2 holding s2
and now p1 waits for for s2 to realsed
and p2 wait for s3 and p3 holds p3 and so on..

there is some way that p1 and p2 can run togther?! or p1 and p4?
Topic archived. No new replies allowed.