![Computers and Technology](/tpl/images/cats/informatica.png)
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](/tpl/images/cats/otvet.png)
Answers: 1
Other questions on the subject: Computers and Technology
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 15:30, micahpauleen748
In a compound condition, both conditions on either side of the logical operator and must be true for the overall condition to be true. a: true b: false
Answers: 1
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 05:00, mariahchaparro08
Which best explains why a digital leader would join a society specializing in technology
Answers: 1
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 07:30, Morganwing1019
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 2
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 17:20, Morehollie9428
What is the best assassins creed game?
Answers: 2
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:
![Konu](/tpl/images/cats/en.png)
![Konu](/tpl/images/cats/en.png)
English, 20.10.2020 03:01
![Konu](/tpl/images/cats/en.png)
![Konu](/tpl/images/cats/mat.png)
Mathematics, 20.10.2020 03:01
![Konu](/tpl/images/cats/istoriya.png)
History, 20.10.2020 03:01
![Konu](/tpl/images/cats/istoriya.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/obshestvoznanie.png)
![Konu](/tpl/images/cats/biologiya.png)