Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

Students also viewed these Databases questions

Question

What are some global employee and labor relations problems?

Answered: 1 week ago

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago