私は、食事の哲学者のパラダイムの例を実装することになっている問題に取り組んでいます。注: はい、これは宿題です。誰かに聞かれる前に。
私は解決策を求めていません。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]);