Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago