subject

Simple Multi-threaded Programming without Synchronization 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 05:00
Are special characters that allow you to search for multiple words at the same time.
Answers: 2
question
Computers and Technology, 22.06.2019 16:20
It policy compliance and emerging technologies respond to the following: propose at least three control measures that organizations need to put in place to ensure that they remain complaint with emerging technologies and in a continually changing it environment. examine the correlation of effective configuration management and change control procedures to remain compliant with emerging technologies and it security changes.
Answers: 2
question
Computers and Technology, 22.06.2019 16:30
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
question
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
You know the right answer?
Simple Multi-threaded Programming without Synchronization First, you need to write a C program usi...
Questions
question
Mathematics, 23.11.2020 19:40
question
Mathematics, 23.11.2020 19:40
question
English, 23.11.2020 19:40
question
Mathematics, 23.11.2020 19:40
question
Mathematics, 23.11.2020 19:40
Questions on the website: 13722362