我正在解决一个问题,我应该实现一个餐饮哲学家范式的例子。注意:是的,这是一个家庭作业,在任何人问之前。
我不是在寻求解决方案。我很困惑,因为Philosopher
我的老师在下面提供的这个功能理论上应该可以工作。wait
并且signal
是 C 中用于 OS 系统调用的函数。
我使用以下方法将它们包括在内:
/* 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]);
}
}
但是,编译时出现错误:
Main.c:38:19: error: too few arguments to function call, expected 2, have 1
signal (Forks[i]);