Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLS follow the requirement and do not copy from others #include #include #include int count; int turn = 0; // Shared variable used to implement

PLS follow the requirement and do not copy from others

image text in transcribed

#include #include #include

int count; int turn = 0; // Shared variable used to implement strict alternation pthread_mutex_t the_mutex;

void* myFunction(void* arg) { int actual_arg = *((int*) arg); for(unsigned int i = 0; i

// Random wait - This code is just to ensure that the threads // show data sharing problems int max = rand() % 100000; for (int x = 0; x

// HINT: It is not necessary to make any changes in main() int main() { int rc[2]; pthread_t ids[2]; int args[2]; count = 0; for(unsigned int i = 0; i

Part 3: Strict Alternation (10 points) 1. A file named pthread-data-sharing-mutex-strict-alternation.cpp has been provided to you in the same project. 2. Compile the program and make sure that it executes. 3. Examine the program code. Note that except for some minor changes, this program is identical to the one you used in Part 2 of this assignment. 4. Modify the program to implement the strict alternation solution to achieve mutual exclusion (refer back to the relevant prep work video/slides if you need to; IMPORTANT NOTE: the outer, infinite while loop in the prep work video/slides is just an example and is not part of the strict alternation solution; only the empty while loop before the call to the critical region and the line immediately following the call to the critical region are part of the strict alternation solution). 5. Build and execute the updated program several times. Expected Output: Your program should produce the following output (Note: it does not matter whether Thread #0 goes first or Thread #1, but it is important that the threads strictly alternate)

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

2. How were various roles filled?

Answered: 1 week ago