dining-philosopher

Dining philosophers problem - only 2 thread worked

…衆ロ難τιáo~ 提交于 2021-01-28 02:21:59
问题 I am trying to solve the dining philosophers problem. In my case, every philosopher should eat 1,000,000 times. The problem is that it seems like only "1" and is "3" finished eating. I am using threads with critical section lock, here is my code: CRITICAL_SECTION ghCARITICALSection1; CRITICAL_SECTION ghCARITICALSection2; CRITICAL_SECTION ghCARITICALSection3; CRITICAL_SECTION ghCARITICALSection4; CRITICAL_SECTION ghCARITICALSection5; DWORD WINAPI func(int* phiphilosopher) { if (1 ==

Dining Philosopher Program C

佐手、 提交于 2020-01-03 06:35:30
问题 I am working with the classic dining philosopher problem with 5 philosophers and 5 chopsticks. My homework is to use 1 mutex and 5 conditions. I got it working but I don't know why philosopher 1 never eats, but 4,3,0 eat and 2 eats twice. Here's my code (sorry for the length): //To compile: gcc -pthread -o monitor monitor.c //To execute: ./monitor "an integer as the amount of food (default = 5)" #include <pthread.h> #include <stdio.h> #include <stdlib.h> // There are 5 philosophers (0,1,2,3,4

possibility of starvation of Dining Philosophers

本小妞迷上赌 提交于 2019-12-31 10:42:12
问题 I need to check my algorithm of solving the dining philosopher problem if it guarantees that all of the following are satisfied or not: No possibility of deadlock. No possibility of starvation. I am using the semaphore on the chopsticks to solve the problem. Here is my code (the algorithm): while(true) { // He is Hungry pickup_chopsticks(i); // He is Eating... drop_chopsticks(i); // He is thinking } // ... void pickup_chopsticks(int i) { if(i % 2 == 0) /* Even number: Left, then right */ {

possibility of starvation of Dining Philosophers

。_饼干妹妹 提交于 2019-12-31 10:42:03
问题 I need to check my algorithm of solving the dining philosopher problem if it guarantees that all of the following are satisfied or not: No possibility of deadlock. No possibility of starvation. I am using the semaphore on the chopsticks to solve the problem. Here is my code (the algorithm): while(true) { // He is Hungry pickup_chopsticks(i); // He is Eating... drop_chopsticks(i); // He is thinking } // ... void pickup_chopsticks(int i) { if(i % 2 == 0) /* Even number: Left, then right */ {