diff --git a/DiningPhilosophers.c b/DiningPhilosophers.c index 9735572..63be6a8 100644 --- a/DiningPhilosophers.c +++ b/DiningPhilosophers.c @@ -86,15 +86,15 @@ void* Philosopher(void* philosopherPassed) PhilosopherData *philosopherSelected = (PhilosopherData*) philosopherPassed; while (true) { - Think(philosopherSelected); /*philosopher is thinking*/ - if (philosopherSelected->eatingCount == 2) + if (philosopherSelected->eatingCount > 2) { - printf("Philosopher %d ate twice...\n", philosopherSelected->position); + // printf("Philosopher %d ate twice...\n", philosopherSelected->position); return; } TakeForks(philosopherSelected); /*acquire two forks or block*/ Eat(philosopherSelected); /*yum-yum, spaghetti*/ PutForks(philosopherSelected); /*put both forks back on table*/ + Think(philosopherSelected); /*philosopher is thinking*/ } } @@ -106,9 +106,10 @@ void PhilosopherInit(int philosopherTotal) sem_init(&semaphore, 0, 1); while (!AllPhilosophersFull(PhilosopherList, philosopherTotal)) { - AllowPhilosopher(); sleep(1); + AllowPhilosopher(); } + sleep(5); for (int i = 0; i < philosopherTotal; i++) { printf("Philosopher %d eating count: %d\n", PhilosopherList[i].position, PhilosopherList[i].eatingCount); @@ -123,6 +124,7 @@ void PhilosopherListInit(PhilosopherData PhilosopherList[], int philosopherTotal PhilosopherList[i].position = i; PhilosopherList[i].eatingCount = 0; PhilosopherList[i].state = THINKING; + printf("Philosopher %d is thinking...\n", i); pthread_create(&PhilosopherList[i].thread, NULL, &Philosopher, &PhilosopherList[i]); } } diff --git a/DiningPhilosophers.out b/DiningPhilosophers.out index af582e6..21e4ff2 100755 Binary files a/DiningPhilosophers.out and b/DiningPhilosophers.out differ