From b47f463204c2bb8d42266b2a5a2e25719529b4d5 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Wed, 28 Sep 2022 15:18:52 -0500 Subject: [PATCH] Adjusted testing --- DiningPhilosophers.c | 22 +++++++++++----------- DiningPhilosophers.out | Bin 0 -> 16472 bytes TestDining.sh | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100755 DiningPhilosophers.out 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 0000000000000000000000000000000000000000..b61488bd582a0c8ef8c12496b96aeffb9aed76ff GIT binary patch literal 16472 zcmeHO4RBP&9pAeo5)?>4C?AR(Rulvdg5gU`xj-(wbOJ<3+R{oNm%B@H!{si$dsjY2 zEO=;p4VlKa+IGen>2w@z>x|fHhiYeohuO6QLM^%4s9l-+$l!?_Qo4 z`Z4WHr*k{=?zjKX-Tm*rcf0THe$`u7<8(L#ry}ubK~#6S$?+(`_m-&)z$2E4vG|=K zZV*?2E|xq~?lA#UGo5k{$5O>F0+QVn%H+Z8O}1d<8WNJ-NNLI_Q^F`zJIJntM2fcK z15zjiBg?bpxyTsFC4Y0M>Ms~AhV-IpBkMLyh#Wuo`68WEyN4OU}S04V2;N{a_Is#uCfxjPo7cP6c z1&nPb4#lJX z<;(SW-0zDtgNBBGtL|^zsyF*WVbLB7MT}-a#?;wM#G1O=Rjc(y?xopWWj43Sy*Qh{ zty1W<4Qus4FcxeH#f@OBVeRU0G!ks^HHE1@Ep5?=s*i4}=2b+)oM>ec?&cz3iOf^G zi^Y1#cwA2og~rn8+oX6CC0#81icU-mVVD#N8VqFf^aBrJxH!cQ> z9VLHQAcS^bx8cn6YRO-h9+vIREWQ`)^O;#mK-mmI`mH26Kk!B-lj)K)P5jOeoXpZR z;X6Ojlci~bc7EU~rr~Xu^j0mTKhX1S^eh`a-9}Hc(iMNHO`ZIbmU>f5o*t}k@K$tJ z9Md{i97m~{Nf+EgTx@oi&7c(y8rZpFDr~jRk_iOM)5at;{Z%MY(?@6e%4X~)y~7Hj zKS09H#cvYKxvZrIwVrb;wVrg5<~X9AylhN_gGZHv(oA1-*$lLc?I}LHS3Co;NX%{2 zk}K||td@Gq7^8KpxF1CSz~xM)KY-vIDd`05*bLiY_5<4>Bu9;~Lua{CyUuEakT0n5w(~4G{^6?)Q6h?)!~uyAJI}h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