OS Lab Assignment 5
OS Lab Assignment 5
1. Write a multithreaded program that calculates various statistical values for a list of numbers. This
program will be passed a series of numbers on the command line and will then create three separate
worker threads. One thread will determine the average of the numbers, the second will determine
the maximum value, and the third will determine the minimum value.
For example, suppose your program is passed the integers: 90 81 78 95 79 72 85
The program will report:
The average value is 82
The minimum value is 72
The maximum value is 95
2. Write a program to create two matrices, A and B, of sizes 40x40, which only take binary inputs 0
and 1. Create two threads running parallel where one thread will compute the summation of the two
matrices and the other will compute their difference. There will be one main thread which will wait
for the two parallel threads to complete their task and it will compute the multiplication of the two
previously obtained output and print the final output.
3. Write a program that receives an arbitrary number of integers as arguments. Let N be the number of
arguments provided by the user. The program creates N threads, each of which is assigned an ID i,
with 0 < i <= N. The ith thread computes a prefix product of all numbers up to and including the ith
argument, i.e. the first thread returns the first number, the second thread computes the product of the
first and second number, and so on. The main thread then waits for all threads to complete and
prints their result in order in the format "product <i> = <product>".
Example output:
Sample Input: 4 3 9 5 21
product 1 = 4
product 2 = 12
product 3 = 108
product 4 = 540
product 5 = 11340