Hey guys, I have a midterm coming up and I am confused on this one question. Any help would be greatly appreciated.

Two processes (P0, P1) are running at the same time. We want to preserve the critical section with two semaphores (S, Q) with initial value 1.

      P1                             P2
   wait(S)                         wait(Q)
   wait(Q)                         wait(S)
//Critical Section              //Critical Section
  signal(S)                       signal(Q)
  signal(Q)                       signal(S)

What is the problem with the solution above and how can you correct this?

Recommended Answers

All 2 Replies

The order that the processes are "waiting" may cause some issues. Look into deadlocks.

In some cases, mutex locks are preferable. Are you allowed to use those? You can simulate a mutex with semaphores, but it isn't simple.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.