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: * Todo:
* Create function up()
* Create function down()
* Create function eat()
* Create function think()
* Add prints to each state change * Add prints to each state change
* Fix each function's requirements
* Theories: * Theories:
* Threads should be put to sleep if can't eat * Threads should be put to sleep if can't eat
* Sleep has to be awoken by something else, process can't wake own thread * 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: // TODO:
// Turn function into putting down forks (releasing waits) // Turn function into picking up forks (starting waits)
// sem_wait // (Right fork is owned by selectedPhilosopher number for consistency)
// Add sem_wait
void Down(pthread_mutex_t selectedSemaphore) void Down(pthread_mutex_t selectedSemaphore)
{ {
printf("Function Down() was called.\n"); 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 // Takes in the number of philosophers, from 0 to N-1
// Finishes when all philosophers have eaten twice // Finishes when all philosophers have eaten twice
// TODO:
// Add splitting function into multiple pthreads
void Philosopher(int numPhilosophers) void Philosopher(int numPhilosophers)
{ {
// Below replaced by PhilosopherData // Below replaced by PhilosopherData
@ -109,11 +109,11 @@ void Philosopher(int numPhilosophers)
int forkCount = numPhilosophers / 2; int forkCount = numPhilosophers / 2;
while (true) while (true)
{ {
break; Think(0); /*philosopher is thinking*/
// Think(0); /*philosopher is thinking*/
// TakeForks(0, numPhilosophers); /*acquire two forks or block*/ // TakeForks(0, numPhilosophers); /*acquire two forks or block*/
// Eat(0); /*yum-yum, spaghetti*/ // Eat(0); /*yum-yum, spaghetti*/
// PutForks(0, numPhilosophers); /*put both forks back on table*/ // PutForks(0, numPhilosophers); /*put both forks back on table*/
break;
} }
} }
@ -161,9 +161,9 @@ void Think(int selectedPhilosopher)
printf("Function Think() was called.\n"); printf("Function Think() was called.\n");
} }
// Pick up for on left and right // Todo:
// (Right fork is owned by selectedPhilosopher number for consistency) // Make function release hold on semaphore
// sem_post // Use 'sem_post'
void Up(pthread_mutex_t selectedSemaphore) void Up(pthread_mutex_t selectedSemaphore)
{ {
printf("Function Up() was called.\n"); printf("Function Up() was called.\n");

BIN
DiningPhilosophers.out Executable file

Binary file not shown.

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
rm DiningPhilosophers rm DiningPhilosophers.out
gcc DiningPhilosophers.c -o DiningPhilosophers gcc DiningPhilosophers.c -o DiningPhilosophers.out
./DiningPhilosophers 5 ./DiningPhilosophers.out 5