Adjusted testing

This commit is contained in:
TriantaTV 2022-09-28 15:18:52 -05:00
parent 31000d2116
commit b47f463204
3 changed files with 14 additions and 14 deletions

View File

@ -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");

BIN
DiningPhilosophers.out Executable file

Binary file not shown.

View File

@ -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