Computers and Technology
Computers and Technology, 11.02.2021 21:50, hjenn31

First, you need to write a C program using the Pthread library to spawn a number of threads each of which executes the loop in the SimpleThread function below. The number of threads to create is a command line parameter passed to your program. All the threads modify a shared variable SharedVariable and display its value within and after the loop. int SharedVariable = 0;
void SimpleThread(int which) {
int num, val = 0;
for(num = 0; num < 20; num++) {
if (random() > RAND_MAX / 2)
usleep(10);
val = SharedVariable;
printf("*** thread %d sees value %d\n", which, val); SharedVariable = val + 1;
}
val = SharedVariable;
printf("Thread %d sees final value %d\n", which, val);
}
Your program must validate the command line parameter to make sure that it is a number.
Your program must be able to run properly with any reasonable number of threads (e. g., 200).
Try your program with the command line parameter set to 1, 2, 5, 10, and 50. Analyze and explain the results.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:30, Angelanova69134
Technician a says that a shop towel should never be used to clean around the flange area before replacing an automatic transmission filter. technician b says that a dimpled transmission fluid pan can be repaired. who is right
Answers: 3
image
Computers and Technology, 23.06.2019 11:00, abdulbasharee99
In the context of the box model, what is the difference between a margin and a padding? a. a padding lies outside a box border, while a margin lies inside it. b. a padding lies inside a box border, while a margin lies outside it. c. a padding can be adjusted independently, while a margin depends on the size of its box. d. a padding depends on the size of its box, while a margin can be adjusted independently.
Answers: 3
image
Computers and Technology, 23.06.2019 14:30, ladawnrowles005
The option enables you to modify a slide element in most presentation applications.
Answers: 2
image
Computers and Technology, 23.06.2019 17:00, evanwall91
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
Do you know the correct answer?
First, you need to write a C program using the Pthread library to spawn a number of threads each of...

Questions in other subjects: