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

Assume a program consists of ten process that differ in the execution speed. Eac

ID: 3814203 • Letter: A

Question

Assume a program consists of ten process that differ in the execution speed. Each process must call a function Fx(); then a function Fy(); however Fy() cannot be called by any process unless all ten process execute Fx() first. Fill in the missing parts of the following pseudo code to show how this could be done using a barrier semaphore B.

n = 10

count = 0;

Semaphore mutex = 1, B = ...;

Fx();

-------------   ( We think that here can be as        wait (mutex);

-------------                                                           count++;

-------------                                                            signal(mutex);

-------------                                                            while (count < n){ };

------------- but B becomes useless )

Fy();

Explanation / Answer

Solution:

To fulfill the given condition we are going to use a loop to execute all the processes of F(x) and when the F(x) is done 10 times the function F(y) can use the resource.

n = 10

count = 0;

Semaphore mutex = 1,

Fx();

wait (mutex);

count++;

signal(mutex); // F(x) will repeat 10 times to complete the process and count will become 10.

if(count==n)

F(y);

wait(B);

signal(B);

I hope this helps. Don't forget to give a thumbs up if you like this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote