Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
There are two processes running on two cores in one CPU (same OS). They are sharing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT