Question: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

 1 2 3 4 5 6 7 8 9 10 11

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/* This code has a problem. It has a critical section that needs to be protected. */ /* compile with gcc problem_job.c -o problem_job */ #include  #include  #include  #include  #include  pthread_t tid[2]; int counter; void* trythis(void* arg) { unsigned long i = 0; counter += 1; printf(" Job %d has started ", counter); for (i = 0; i  

1-Theres a problem with the code in problem_job.c . What is it?

2- Change the code in problem_job.c so that the problem is fixed by using a mutex lock. (Use calls to functions such as pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock, pthread_mutex_destroy.). Put your fixed program into a file called mutex_fix.c . Show me your new fixed code. Compile and run the new code to show that you have fixed the problem successfully. Add this proof to your homework solution document.

6 #include 7 #include 8 #include 9 #include 10 #include 11 12 pthread_t tid[2]; 13 int counter; 14 15 void* trythis(void* arg) 16 { 17 unsigned long i = 0; 18 counter += 1; 19 printf(" Job %d has started ", counter); 20 21 for (i = 0; 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!