Tag: 餐饮哲学家

餐饮哲学家计划C.

我正在与5位哲学家和5根筷子一起处理经典的餐饮哲学家问题。 我的作业是使用1个互斥量和5个条件。 我得到了它的工作,但我不知道为什么哲学家1从不吃,但4,3,0吃,2吃两次。 这是我的代码(抱歉长度): //To compile: gcc -pthread -o monitor monitor.c //To execute: ./monitor “an integer as the amount of food (default = 5)” #include #include #include // There are 5 philosophers (0,1,2,3,4) and 5 chopsticks (0,1,2,3,4) #define NUM 5 // States of a philosopher #define THINKING 0 #define HUNGRY 1 #define EATING 2 int […]