subject
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.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
question
Computers and Technology, 23.06.2019 17:30
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
Which feature of a blog to restore and retrieve older post
Answers: 3
You know the right answer?
First, you need to write a C program using the Pthread library to spawn a number of threads each of...
Questions
question
Chemistry, 03.02.2020 01:53
question
Mathematics, 03.02.2020 01:53
question
Mathematics, 03.02.2020 01:53
question
English, 03.02.2020 01:53
Questions on the website: 13722361