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 user-defined function except Pthread API.
Int global=10;
Int K=5;
void process(int rank, char mod)
/*the mode=R reading or mode =W writing*/
{
/*the following should be executed by master threads only*/
Global+=rank;
/*the following should be executed only by one thread at a time*/
Printf(global =%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*/
Printf(%d
, 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!