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 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 45 46 47 48 49 50
#include  #include  #include  /* compile with gcc mutex_switch.c -o mutex_switch */ #define COUNT_TO 100000 #define MAX_CORES 12 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; long long i = 0; void *start_counting(void *arg) { for (;;) { // acquire lock pthread_mutex_lock(&mutex); // check if all COUNT_TO has been arrived at if (i >= COUNT_TO) { pthread_mutex_unlock(&mutex); return NULL; } ++i; // release lock pthread_mutex_unlock(&mutex); printf("i = %lld ", i); } } int main(void) { int i = 0; // create a thread group the size of MAX_CORES pthread_t *thread_group = malloc(sizeof(pthread_t) * MAX_CORES); // start all threads to begin work for (i = 0; i < MAX_CORES; ++i) { pthread_create(&thread_group[i], NULL, start_counting, NULL); } // wait for all threads to finish for (i = 0; i < MAX_CORES; ++i) { pthread_join(thread_group[i], NULL); } return EXIT_SUCCESS; } 

Change the code in mutex_swith.c so that it is written/configured exactly correctly for the architecture of your computer. Compile and run the new code. Document in any way you choose that your code is properly configured for your computer. Add this proof to your homework solution document.

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!