Consider a multicore system and a multithreaded program writtenusing the many-to-many | StudySoup

Textbook Solutions for Operating System Concepts

Chapter 4 Problem 4.18

Question

Consider a multicore system and a multithreaded program writtenusing the many-to-many threading model. Let the number of user-levelthreads in the program be greater than the number of processing coresin the system. Discuss the performance implications of the followingscenarios.a. The number of kernel threads allocated to the program is less thanthe number of processing cores.b. The number of kernel threads allocated to the program is equal tothe number of processing cores.c. The number of kernel threads allocated to the program is greaterthan the number of processing cores but less than the number ofuser-level threads. #include #include #include int value = 0;void *runner(void *param); /* the thread */int main(int argc, char *argv[]){pid t pid;pthread t tid;pthread attr t attr;pid = fork();if (pid == 0) { /* child process */pthread attr init(&attr);pthread create(&tid,&attr,runner,NULL);pthread join(tid,NULL);printf("CHILD: value = %d",value); /* LINE C */}else if (pid > 0) { /* parent process */wait(NULL);printf("PARENT: value = %d",value); /* LINE P */}}void *runner(void *param) {value = 5;pthread exit(0);}F

Solution

Step 1 of 3)

The first step in solving 4 problem number 18 trying to solve the problem we have to refer to the textbook question: Consider a multicore system and a multithreaded program writtenusing the many-to-many threading model. Let the number of user-levelthreads in the program be greater than the number of processing coresin the system. Discuss the performance implications of the followingscenarios.a. The number of kernel threads allocated to the program is less thanthe number of processing cores.b. The number of kernel threads allocated to the program is equal tothe number of processing cores.c. The number of kernel threads allocated to the program is greaterthan the number of processing cores but less than the number ofuser-level threads. #include #include #include int value = 0;void *runner(void *param); /* the thread */int main(int argc, char *argv[]){pid t pid;pthread t tid;pthread attr t attr;pid = fork();if (pid == 0) { /* child process */pthread attr init(&attr);pthread create(&tid,&attr,runner,NULL);pthread join(tid,NULL);printf("CHILD: value = %d",value); /* LINE C */}else if (pid > 0) { /* parent process */wait(NULL);printf("PARENT: value = %d",value); /* LINE P */}}void *runner(void *param) {value = 5;pthread exit(0);}F
From the textbook chapter Threads you will find a few key concepts needed to solve this.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Operating System Concepts  9 
Author Abraham Silberschatz, Peter B. Galvin, Greg Gagne
ISBN 9781118063330

Consider a multicore system and a multithreaded program writtenusing the many-to-many

Chapter 4 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back