Process A Process B Process C Process D for (; X < 4; X++) { while (X < 4) { while (X< 4) { while (Y< 3) { cout << X; cout << "a"; cout << "c"; cout << Y; cout << "b"; cout << "b"; Y++; } } } } Q3/(6 marks) Let us define three threads run concurrently, using system call function (Test and Set) to satisfy conditions of process competition problem and to get correct answer (using four system variables b1, b2, b3, b4). Thread 3 Thread 2 Thread 1 Y=X-20; Int Z=3; Int Y=6; X=X-Y; X=Z+2; Int X=Y+5; Int M=N+L; Int B=5-Y; Y=X+10; Print M; Int L=B-2; Int C=10; Print L; Int N=C+1; N; Let bool F1=True; bool F2=True; bool F3=True; bool F4=True; Thread 3 Thread 2 Thread 1 While(T_S(&F1)); Int Z=3; Int Y=6; Y=X-20; While(T_S(&F2)); Int X=Y+5; X=X-Y; X=Z+2; Y=X+10; While(T_S(&F3)); Int B=5-Y; Int M=N+L; F1=false; Int C=10; Print M; While(T_S(&F4)); Int N=C+1; Int L=B-2; F4=false F3=False; Print N; Print L;
Process A for (; X < 4; X++) { cout << X; } Process B while (X < 4) { cout << "a"; cout << "b"; } Process C while (X< 4) { cout << "c"; cout << "b"; } Process D while (Y< 3) { cout << Y; Y++; } Q3/(6 marks) Let us define three threads run concurrently, using system call function (Test and Set) to satisfy conditions of process competition problem and to get correct answer (using four system variables b1, b2, b3, b4). Thread 3 Thread 2 Thread 1 Y=X-20; X=X-Y; Int M=N+L; Print M; Int Z=3; X=Z+2; Int B=5-Y; Int L=B-2; Print L; Int Y=6; Int X=Y+5; Y=X+10; Int C=10; Int N=C+1; N; Let bool F1=True; bool F2=True; bool F3=True; bool F4=True; Thread 3 Thread 2 Thread 1 While(T_S(&F1)); Y=X-20; X=X-Y; While(T_S(&F3)); Int M=N+L; Print M; Int Z=3; While(T_S(&F2)); X=Z+2; Int B=5-Y; F1=false; While(T_S(&F4)); Int L=B-2; F3=False; Print L; Int Y=6; Int X=Y+5; Y=X+10; Int C=10; Int N=C+1; F4=false Print N;