4
$\begingroup$

I have been posed a question by my lecturer and I'm trying to figure the right way to go about it. They want me to ensure mutual exclusion for n processes. The code provided is as follows:

Process Pi
    while(true){
            while(#taken == 5){}

            #taken := #taken+1;
            // enjoy a non-alcoholic drink //

            #taken := #taken-1;         
        }
    }

The task provided is Add synchronization code such that the requirements for the bar are enforced. i.e. only five people at the bar at a time. Assuming n processes how can I make sure that only one process can enter the critical section at a time? I've tried this:

s = 1
Process Pi
    while(true){
        if(s > 0){
            while(#taken == 5){}

            #taken := #taken+1;
            // enjoy a non-alcoholic drink //

            #taken := #taken-1;
            s=s-1
            }
        }
    }

But it doesn't appear to me mutually exclusive. They also said this in a study group this evening:

You may also assume the existence of mutual exclusion variables that support the operations preprotocol(mutex) and postprotocol(mutex) to create critical sections.

I don't really understand what this means. Would anyone be able to shed any light on this issue?

$\endgroup$
  • $\begingroup$ How have preprotocol() and postprotocol() been defined? $\endgroup$ – Klaus Draeger Nov 7 '14 at 15:33
  • $\begingroup$ The statements "only 5 people are allowed at the bar" and "only 1 person is allowed to be in critical section" seems contradicting $\endgroup$ – arunmoezhi Nov 9 '14 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.