//This model is an adaptation by Camil Staps of
//an adaption by Frits Vaandrager of
//a model made by Martijn Hendriks
// Number of processes in system:
const int N = 5;
const int emptyPot = 0;
const int fullPot = 1;
const int mutex = 2;
const int nr_sem = 3; // nr. of semaphores
int servings = 5;
const int max_servings = 5;
// The channels to synchronize with the semafores
// A call semWait(s) by process p translates to a sequence of two transitions labeled with
// semWait(s)(p)!
// semGo(s)(p)?
//A call semSignal(s) by process p translates to a transition labeled with
// semSignal(s)(p)!
chan semWait[nr_sem][N], semGo[nr_sem][N], semSignal[nr_sem][N];Semaphoreconst int id, const int queue_size, const int init_val//The value of the semaphore
int count = init_val;
//The queue of the semaphore
//value -1 denotes an empty array entry
int[-1,N-1] queue[queue_size];
//An auxiliary variable used to temporarily store process id
meta int[0,N-1] q;
void initialize ()
{
for (i : int[0,queue_size-1])
{queue[i] = -1;}
}
void deQueue ()
{
for (i : int[1,queue_size-1])
queue[i-1] = queue[i];
queue[queue_size-1] = -1;
}
void enQueue (int p)
{
int i = 0;
while (queue[i]>=0){i++;};
queue[i]=p;
}
int[0,N-1] headQueue ( )
{
return queue[0];
}
bool fullQueue ( )
{
for (i : int[0,queue_size-1])
{
if (queue[i]==-1) {return false;}
}
return true;
}overflowCookconst int pidputnotifysleepSavageconst int pidleave_mutexmutex_waiteatwait_for_cookwake_cookhungryEmptyPot = Semaphore(emptyPot, N-1, 0);
FullPot = Semaphore(fullPot, N-1, 0);
cook = Cook(0);
Mutex = Semaphore(mutex, 5, 1);
s1 = Savage(0);
s2 = Savage(1);
s3 = Savage(2);
s4 = Savage(3);
system EmptyPot, FullPot, Mutex, cook, s1, s2, s3, s4;