/************************************************************ File: solution2.cc Description: A program that simulates the problem of the five philosophers. Author: Dana Vrajitoru Organization: IUSB Date: August 22, 2018 **************************************************************/ #include #include using namespace std; #include #include "solution2.h" int forks[PHIL_NR] = {1, 1, 1, 1, 1}, id=0, iterations=0; pthread_mutex_t forks_sem[PHIL_NR], id_sem, cout_sem; int meditated[PHIL_NR] = {0, 0, 0, 0, 0}, eaten[PHIL_NR] = {0, 0, 0, 0, 0}; // Initializes all the semaphores we need. void Init_semaphores() { pthread_mutex_init(&id_sem, NULL); //pthread_mutex_unlock(&id_sem); for (int i=0; i> iterations; } // Waits for a random amount of time between two limits. void Wait() { static const int LOW = 10000, HIGH=20000; int cycles = LOW + rand()%(HIGH - LOW); double j; for (int i=0; i