There are two processes running on two cores in one CPU same

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.

Solution

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); }

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) { te

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site