diff --git a/DiningPhilosophers.c b/DiningPhilosophers.c index 60f938b..0043908 100644 --- a/DiningPhilosophers.c +++ b/DiningPhilosophers.c @@ -33,11 +33,8 @@ void Up(pthread_mutex_t selectedSemaphore); /* * Todo: - * Create function up() - * Create function down() - * Create function eat() - * Create function think() * Add prints to each state change + * Fix each function's requirements * Theories: * Threads should be put to sleep if can't eat * Sleep has to be awoken by something else, process can't wake own thread @@ -70,8 +67,9 @@ bool AllPhilosophersFull(PhilosopherData PhilosopherList[], int numPhilosophers) // // TODO: -// Turn function into putting down forks (releasing waits) -// sem_wait +// Turn function into picking up forks (starting waits) +// (Right fork is owned by selectedPhilosopher number for consistency) +// Add sem_wait void Down(pthread_mutex_t selectedSemaphore) { printf("Function Down() was called.\n"); @@ -98,6 +96,8 @@ int GetNumberPhilosophers(char* argv) // Takes in the number of philosophers, from 0 to N-1 // Finishes when all philosophers have eaten twice +// TODO: +// Add splitting function into multiple pthreads void Philosopher(int numPhilosophers) { // Below replaced by PhilosopherData @@ -109,11 +109,11 @@ void Philosopher(int numPhilosophers) int forkCount = numPhilosophers / 2; while (true) { - break; - // Think(0); /*philosopher is thinking*/ + Think(0); /*philosopher is thinking*/ // TakeForks(0, numPhilosophers); /*acquire two forks or block*/ // Eat(0); /*yum-yum, spaghetti*/ // PutForks(0, numPhilosophers); /*put both forks back on table*/ + break; } } @@ -161,9 +161,9 @@ void Think(int selectedPhilosopher) printf("Function Think() was called.\n"); } -// Pick up for on left and right -// (Right fork is owned by selectedPhilosopher number for consistency) -// sem_post +// Todo: +// Make function release hold on semaphore +// Use 'sem_post' void Up(pthread_mutex_t selectedSemaphore) { printf("Function Up() was called.\n"); diff --git a/DiningPhilosophers.out b/DiningPhilosophers.out new file mode 100755 index 0000000..b61488b Binary files /dev/null and b/DiningPhilosophers.out differ diff --git a/TestDining.sh b/TestDining.sh index 2973cc9..0e60c98 100755 --- a/TestDining.sh +++ b/TestDining.sh @@ -1,4 +1,4 @@ #!/bin/bash -rm DiningPhilosophers -gcc DiningPhilosophers.c -o DiningPhilosophers -./DiningPhilosophers 5 +rm DiningPhilosophers.out +gcc DiningPhilosophers.c -o DiningPhilosophers.out +./DiningPhilosophers.out 5