Hack Forums
[C] precedence graph with semaphores - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] precedence graph with semaphores (/showthread.php?tid=6128585)



precedence graph with semaphores - georgeziozas - Dec 20, 2020

🙃Hey there, I am working on system programming for the last weeks, and I'm trying to grasp some major concepts.
I am writing C in Linux OS.

P1 process code:
Code
while(true){
print(P)
print(I)
}

P2 process code:
Code
while(true){
print(Z)
}

P3 process code:
Code
while(true){
print(A)
}

I have achieved to use P and V semaphores to print PIZZA once with the code below:

Code
var Σ12, Σ13, Σ23: semaphores;
Σ12:= Σ13:= Σ23:= 0;
cobegin
begin Δ1; V(Σ12); V(Σ13); end;
begin P(Σ12); Δ2; V(Σ23);end;
begin P(Σ13);P(Σ23); Δ3;end;
coend

What if I want to use the same 3 semaphores to print :

Code
PIZZAPIZZAPIZZAPIZZA.......
(forever).

Thanks in advance. ✌