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

There are two processes running on two cores in one CPU (same OS). They are shar

ID: 3936068 • Letter: T

Question

There are two processes running on two cores in one CPU (same OS).

They are sharing a memory location called “share” (with a start value of 0).

P: while(1) { temp = share; temp = temp + 1; share = temp; }

C: while(1) { temp = share; cout << temp; }

• We want print the numbers: 1,2,3,4,5 etc consecutively with no gaps. Using a binary semaphore called “s” and the semaphore operations:

signal(s) – which indicates the semaphore (resource) will be used and

wait(s) – which waits until the resource is available,

modify P and C to print, in order.

Explanation / Answer

We use semaphore to acquire shared resources so that no RACE condition arrives. So in this question, while reading or writing into 'share' vairable we have to use semaphore.

P: while(1) { signal(s);temp = share; wait(s);temp = temp + 1;signal(s) share = temp;wait(s) }

C: while(1) { signal(s);temp = share; wait(s); }

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