Question: This is an Operating systems problem. Please provide the answer type out. Example code from Chapter 4 to help start the problem: Write a C/C++

This is an Operating systems problem. Please provide the answer type out.

This is an Operating systems problem. Please provide the answer type out.

Example code from Chapter 4 to help start the problem:

Example code from Chapter 4 to help start the problem: Write a

Write a C/C++ program that creates a thread that generates a random number between 0 and 1 and prints out the generated random number. You may want to refer to the code example in the course slides of Chapter 4 to get started. #include #include int sum; /* this data is shared by the thread(s) */ void *runner(void *param); /* threads call this function */ int main(int argc, char *argv []) { pthread_t tid; /* the thread identifier */ pthread_attr_t attr; /* set of thread attributes */ if (argc != 2) { fprintf(stderr, "usage: a.out "); return -1; } if (atoi(argv[1]) = 0 ", atoi(argv[1])); return -1; ** * get the default attributes */ pthread attr init(&attr); /* create the thread */ pthread_create(&tid,&attr,runner, argv[1]); /* wait for the thread to exit */ pthread_join(tid,NULL); printf("sum = %d ", sum); } /* The thread will begin control in this function */ void *runner(void *param) { int i, upper = atoi(param); sum = 0; for (i = 1; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!