Multithreading | Sololearn: Learn to code for FREE!


How to fix the code so that there is no deadlock? process INIT; common boolean C1. C2; common integer N; common real T1, T2; begin –°1:=false; –°2:=false; T1:= random; T2:= random; N:=1; start(P1); start(P2); end; process P1; Begin while true do begin BEFORE1; C1:=true; while C2 and (N<>1) do delay(T1); CS1; C1:=false; N:=2; AFTER1; end end; process P2; Begin while true do begin BEFORE2; C2:=true; while C1 and (N<>2) do delay(T2); CS2; C2:=false; N:=1; AFTER2; end end;

13th Jun 2020, 8:49 AM
Mary_d9 - avatar
1 Réponse
+ 1
In principle, I think both subprocesses should release all resources if they cannot immediately allocate all resources. Or at least release them after a limited number of attempts.
17th Jun 2020, 8:52 PM
Brian - avatar