Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can somebody explain to me how to solve problems like below I need as much detai

ID: 3546958 • Letter: C

Question

Can somebody explain to me how to solve problems like below I need as much details as possible


var a b c d e f g semaphores

(initial value of all semaphores is 0)

begin

               parbegin

                    begin S1 V(a) V(b) end

                   begin P(a) S2 S4 V(c) V(d) end

                   begin P(b) S3 V(e) end               

                   begin P(c) S5 V(f) end                

                   begin P(d) P(e) S6 V(g) end               

                   begin P(f) P(g) S7  end           

               Parend

           end     

var a b c d e f g semaphores (initial value of all semaphores is 0) begin parbegin begin S1 V(a) V(b) end begin P(a) S2 S4 V(c) V(d) end begin P(b) S3 V(e) end begin P(c) S5 V(f) end begin P(d) P(e) S6 V(g) end begin P(f) P(g) S7 end Parend end

Explanation / Answer


first, once look at the flow (from flow diagram) we can notice that

without completion of S1 we cant reach S2 or S3

similarly to reach S4 we should first complete S2


from the code above we can notice that we used two signal() or V() operations after S1 -- V(a),V(b) --in line 3

after that in line 4 -- before we start S2 and S4 we used P(a) operation ..as S2 and S4 are executed in series or one after other they are written in the same block and if S1 is not executed then value of semaphore a=0 but as S1 is executed value of a=1 because there is V(a) after S1 which will help us to execute S1,S2,S4 in flow ,because if a=0, then we can not execute S2,S4 as it would be blocked by P(a) operation


similarly in line 5 -P(b) is used ,where b=1 if S1 is executed as there is V(b) and with out execution of S1 the value of b=0 so

P(b) will block us


line 6--to execute S5 first we should execute S4 so we used a V(c) operation and we do P(c) before we execute S5


line 7--S6 can be reached through 2 ways one way is from S3 and another is S4 so we use V(d) after S4 and V(e) after S3

and P(d) P(e) is operated before executing S6 so from this if we did not execute any of these (S4 or S3) we can not execute S6


line 8--similarly like S6 even for S7 we have 2 ways one from S5 and another from S6 so we do V(f) andV(g) after S5 andS6 respectively and we do P(f)P(g) before executing S7 so if didnot execute S5orS6 we cant execute S7


this may help u!! thankyou