Question: Question 1 The following program in Erlang implements the Producers / Consumers synchronization pattern using message passing. It is missing the implementation of loopPC /

Question 1 The following program in Erlang implements the Producers/Consumers synchronization pattern using message passing. It is missing the implementation of loopPC/4 which you are asked to complete. The arguments to loopPC are as follows: - Cs: Number of consumers that started consuming - Ps: Number of producers that started producing - MaxBuffersize: Buffer size (constant, greater than 0)- OccupiedSlots: Number of currently occupied slots in the buffer Note: Multiple producers and consumers should be allowed. consumer (Id, Buffer)-> timer : sleep (200), io: fwrite (" Consumer p trying to consume n^'',[I d]), Ref = make_ref (), Buffer !{ start_consume, self (), Ref }, receive {ok_to_consume, Ref -> io: fwrite (" Consumer p consuming . n^'',[I d]), Buffer !{ end_consume }, io: fwrite ("Consumer p stopped consuming . n^'',[I d]), consumer (Id, Buffer) end producer (Id , Buffer)-> timer : sleep (1000), io: fwrite (" Producer p trying to produce n^'',[ Id ]), Ref = make_ref (), Buffer !{ start_produce, self (), Ref}, receive { ok_to_produce, Ref}-> io: fwrite (" Producer p producing n^'',[I d]), Buffer !{ end_produce }, io: fwrite ("Producer p stopped producing . n^'',[I d]), producer (Id , Buffer) end loopPC (Cs, Ps, MaxBufferSize, 0ccupiedSlots)->%% implement me startPC ()-> Buffer = spawn ( fun ()->loopPC(0,0,10,0) end ),[ spawn ( fun ()-> producer (Id , Buffer) end)|| Id <- lists : seq (1,10)],[ spawn ( fun ()-> consumer (Id, Buffer) end) Id <- lists: seq (1,10)].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!