0

I am trying to understand the concepts of Semaphores, I have the following piece of code. Initially Semaphore mutex is initialized to 1

 Structure of Pi;
do{
wait(mutex);
Critical Section
signal(mutex);
Remainder section
}
while(1);

Considering N processes, does the above algorithm provides a good solution to the Critical Section problem?

My observation is that the first two conditions, i.e Mutual exclusion and Progress are being satisfied but not the bounded buffer. Is that correct?

halfer
  • 19,824
  • 17
  • 99
  • 186
Faizan
  • 1,847
  • 8
  • 40
  • 63

1 Answers1

2

Mutual exclusion is being satisfied if the semaphore maximum count is 1. Typically you would use a lock if you want mutual exclusion.

Progress isn't necessarily being satisfied. It depends on if the semaphore implementation guarantees fairness. On some operating systems, given two high priority threads and one with lower priority, it's possible for the low priority thread to be starved.

The bounded buffer problem is not being satisfied, but then what you show is not a producer-consumer program.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351