I am working on a problem where I am supposed to implement an example of the dining philosopher paradigm. Note: Yes this a homework assignment, before anyone asks.
I am not asking for a solution though. I am confused because this Philosopher
function that was supplied below by my teacher is theoretically supposed to work. wait
and signal
are the function used in C for OS system calls.
I have included them using:
/* Wait and Signal */
#include <signal.h>
#include <sys/wait.h>
struct semaphore
{
int count = 1;
struct PCB *Sem_Queue ;
};
struct semaphore Forks[5];
Philosopher()
{
i = getPID() ;
while (1)
{
think ();
wait (Forks[i]);
wait (Forks[(i+1) % 5]);
eat ();
signal (Forks[i]);
signal (Forks[(i + 1) % 5]);
}
}
However, when compiled I get the error:
Main.c:38:19: error: too few arguments to function call, expected 2, have 1
signal (Forks[i]);
It appears that the wait()
and signal()
functions called by Philosopher()
are like the think()
and eat()
functions -- intended to be provided by you (or else included with Philosopher()
). The name clash between those and two POSIX functions is unfortunate and confusing, but not meaningful.
Do not include signal.h
or sys/wait.h
. Instead, provide declarations, by header file or otherwise, for your functions of those names, and make sure your implementations are linked into the executable.