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 02:00
Aletter or menu command that starts an action when the user presses the designated letter and the alt key together is called what?
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
The editing of digital photos us about the same level of difficulty as editing an analog photo
Answers: 2
question
Computers and Technology, 22.06.2019 15:20
The north and south regions had very diferent economies in the 1800s.
Answers: 1
question
Computers and Technology, 22.06.2019 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
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
Arts, 16.12.2021 01:00
question
Biology, 16.12.2021 01:00
Questions on the website: 13722361