Question: Consider the following function process ( ) . Consider that there are N threads, each thread starting with this function. Master thread is one with
Consider the following function process Consider that there are N threads, each thread starting with this function. Master thread is one with rank zero. Write the modified function may delare any global variables above the function for the requirements given below. Please do not use any userdefined function except Pthread API.
Int global;
Int K;
void processint rank, char mod
the modeR reading or mode W writing
the following should be executed by master threads only
Globalrank;
the following should be executed only by one thread at a time
Printfglobal d
global;
the following code area should be entered exactly by three threads only, not one, two or more than three
Printf
;
the following code area rule: if the mode is R then it is allowed only if there is no thread for W in the area. If the mode is W then it is allowed only if there is no thread with R in the area
Printfd
K; executed by thread with mode R
K; executed by thread with mode W
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
