Question: A4q2.c code: #include #include #include int sum = 0; /* this data is shared by the thread(s) */ /* Thread task */ void *ThreadTask(void *arg)

A4q2.c code:

#include  #include  #include  int sum = 0; /* this data is shared by the thread(s) */ /* Thread task */ void *ThreadTask(void *arg) { int k,m; for (k=1; k 

Consider the C program A4q2.c which is available in the Google Classroom. In this program, four worker threads are created whose names are A, B, C, D. The task for each thread is to print its name on the screen 100 times. When we run this C program, their print-out names are interleaved as shown below.

A4q2.c code: #include #include #include int sum = 0; /* this data

Revise the C program A4q2.c by apply the pthread mutex subroutines such that there is no interleaving. When a worker thread prints its name, it will continue until it finishes. The order that which thread prints first and next is not matter (e.x., you might have C -> B -> A -> D or A -> C - > D -> B or etc.). For example, you might have this order:

is shared by the thread(s) */ /* Thread task */ void *ThreadTask(void

put the revised code below

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!