Question

Suppose there are three threads P, Q and R, each has some sequential code sections and then updates a shared variable count, as shown in the below table. Define and initialize semaphores to solve the synchronization and the critical section problems (use acquire/release or wait/signal) Assume that QS1 needs to be executed after PS1 and RS1, and PS2 needs to be executed after QSl RS2 needs to be executed after QS2 which needs to be executed after PS2 /* Semaphores and initial Values:/ Spt R. 10pt PS1 ) osi ) RS1 ) PS2 OS2 ) RS2 count-count3 count-count2 y count + 5 Spt

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

1- semaphore is a abstract dat type or we can say that protected variable which contain the method for restricting access to shared resources like p ,q,r share the resource in which shared memory work as a parallel programming a certain area.

QS1 needs to be executed after PS1 and RS1

like PS2 NEEDS TO BE EXECUTED AFTER QS1

in which process will apply the busy wait Semaphore:-

  • The simplest way to imlement wait() semaphore for process.
  • S is a integer value,it can initialized the positive value and that can be access critical section and mutually eclusive operation;-
    • wait (s)
    • while s. value=10
    • s.value--
    • signal(s)

s.value++

synchronozatin problem that can affect or by other processes

in which process may be either shared a logical address space and shared data through files. so critical section solution can be used and it is ensure the consistency of process.

this process can be solve by critical parts of our code that can be executed one time one process untill other process will do wait for release the resource.

//critical section ps1#

wait until flag synchronize

//do critical ps1 synchronize

same this process to happen for each process for each resources it means every process will do wait untill it will not get release resources.

Add a comment
Know the answer?
Add Answer to:
Suppose there are three threads P, Q and R, each has some sequential code sections and...
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
  • operating system engineering , please read the question and solve on the given skeleton code ....

    operating system engineering , please read the question and solve on the given skeleton code . Write a multi-threaded program with Semaphores as counters and pthread_mutex_t mutex to solve the producer-consumer problem: A bounded buffer is simply a global integer array of size N (2) which can be accessed by multiple threads. • Create two types of threads - Producer (2) and Consumer (2). Producers will write to the buffer, and the consumers will read the buffer. In this scenario,...

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