Question: What are the three requirements for a solution to the critical-section problem? Consider the following solution to the dining-philosophers' problem. // Global variables. Shared among


What are the three requirements for a solution to the critical-section problem? Consider the following solution to the dining-philosophers' problem. // Global variables. Shared among threads int state [5]; semaphore mutex; I/ Initially set to 1 semaphore s [5] I Initially s[i] is set to 0 for all i Initially statei]-THINKING for all i void philosopher (int i) f int left(int i) f // Philosopher to the left of i // % is the mod operator. while(TRUE) thinkO take.forks () eat O return (i + 4) % 5; put.forks() int right(int i) ( // Philosopher to the right of i return (i + 1) % 5; void take.forks (int i) [ P(utex) state[i]-HUNGRY test (i): void test (int ) [ (state [i] if && HUNGRY state [left (i)] !-EATING && state[right()EATING) I := V(mutex) state []-EATING: void put forks (int i) ( P(nutex) state[i]THINKING; test (left (i)) test (right() V(utex)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
