Question: First, you need to write a C program using the Pthreads library that forks a few threads each executes the loop in the Simple Thread

First, you need to write a C program using the Pthreads library that forks a few threads each executes the loop in the Simple Thread function below. The number of threads is a command line parameter of your program. All the threads modify a shared variable Shared Variable and display its value within and after the loop. int Shared Variable = 0; void SimpleThread(int which) { int num, val; for(num = 0; num RAND_MAX/2) usleep(500); val = Shared Variable; printf("*** thread %d sees value %d ", which, val); Shared Variable = val + 1; } val = Shared Variable; printf("Thread %d sees final value %d ", which, val); } Your program must validate the command line parameter to make sure that it is a number, not an arbitrary string. 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, 3, 4, and 5. Analyze and explain the results. Put your explanation in your project report
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
