Provide two programming examples in which multithreading provides better performance than a single-threaded solution.
Read moreTable of Contents
Textbook Solutions for Operating System Concepts
Question
Write a multithreaded program that calculates various statistical valuesfor a list of numbers. This program will be passed a series of numbers onthe command line and will then create three separate worker threads.One thread will determine the average of the numbers, the secondwill determine the maximum value, and the third will determine theminimum value. For example, suppose your program is passed theintegers90 81 78 95 79 72 85The program will reportThe average value is 82The minimum value is 72The maximum value is 95The variables representing the average, minimum, and maximum valueswill be stored globally. The worker threads will set these values, and theparent thread will output the values once the workers have exited. (Wecould obviously expand this program by creating additional threadsthat determine other statistical values, such as median and standarddeviation.)
Solution
The first step in solving 4 problem number 21 trying to solve the problem we have to refer to the textbook question: Write a multithreaded program that calculates various statistical valuesfor a list of numbers. This program will be passed a series of numbers onthe command line and will then create three separate worker threads.One thread will determine the average of the numbers, the secondwill determine the maximum value, and the third will determine theminimum value. For example, suppose your program is passed theintegers90 81 78 95 79 72 85The program will reportThe average value is 82The minimum value is 72The maximum value is 95The variables representing the average, minimum, and maximum valueswill be stored globally. The worker threads will set these values, and theparent thread will output the values once the workers have exited. (Wecould obviously expand this program by creating additional threadsthat determine other statistical values, such as median and standarddeviation.)
From the textbook chapter Threads you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution