/************************************************************ File: solution2.h Description: A program that simulates the problem of the five philosophers. Author: Dana Vrajitoru Organization: IUSB Date: August 22, 2018 **************************************************************/ #ifndef SOLUTION2_H #define SOLUTION2_H #include const int PHIL_NR = 5; // Initializes all the semaphores we need. void Init_semaphores(); // Inputs the number of iterations for each philosopher. void Input_iters(); // Waits for a random amount of time between two limits. void Wait(); // Increases the meditation count and waits. void Meditate(); // Increases the eating count and waits. void Eat(); void Write(char *str); // Tries to reserve a fork. If it can, it reserves it and returns 1, // otherwise returns 0. int Try_to_reserve(int fork_nr); // Releases a fork. void Release(int fork_nr); // The second solution in the heandouts for the philosophers problem. void Philosopher(int id); // The main thread function. Each of the threads gets an id between 0 // and the number of philosophers and then calls the Philosopher // function with this id. void *Get_id_and_run(void *ignored); // The function that creates all of the threads. void Create_threads(pthread_t *threads); // A function that synchronizes all of the threads. void Synchronise(pthread_t *threads); // Output the statistics for each philosopher. void Write_stats(); #endif