Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#define LOG_PV(func, sem, proc) \
printf("["#proc"] before "#func"("#sem") = %d\n", sem_getval(sem));\
func(sem);\
printf("["#proc"] after "#func"("#sem") = %d\n", sem_getval(sem));
#define LOG_P(sem, proc) \
LOG_PV(P, sem, proc)
#define LOG_V(sem, proc) \
LOG_PV(V, sem, proc)
//Producer process
if(pid > 0)
{
while(1)
{
LOG_P(emptyShelf, Waiter);
LOG_P(mutex, Waiter);
waiter_as_producer();
LOG_V(mutex, Waiter);
LOG_V(orderOnShelf, Waiter);
LOG_P(pizzaOnShelf, Waiter);
LOG_P(mutex, Waiter);
waiter_as_consumer();
LOG_V(mutex, Waiter);
LOG_V(emptyShelf, Waiter);
}
}
if(pid == 0)
{
while(1)
{
LOG_P(orderOnShelf, Cook); // make sure there is an order on shelf
LOG_P(mutex, Cook); //permission to work
cooker_as_consumer(); // take order and put pizza on shelf
LOG_V(mutex, Cook); //release permission
LOG_V(pizzaOnShelf, Cook); // pizza is now on shelf
}
}
int sem_getval(int semid) {
union semun s;
return semctl(semid, 0, GETVAL, s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.