Question: Part I: [ 7 points | Write a multithreaded program in Java that calculates various statistical values for a list of numbers. This program will
Part I: points
Write a multithreaded program in Java 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 sum of the numbers, the
second will calculate the average of the numbers, and the third will determine the maximum value.
The parent thread should output the values once the workers have exited.
For example, suppose your program is passed these integers:
java yourprogram
The program should print:
Sum
Average
Max
Part II: marks
A marks Write a C program where multiple threads eg threads each increment a
shared counter by one times. Compile and run your program several times at least runs
are recommended Provide screenshots of the output from multiple runs. Discuss briefly in your
report why the final counter value is not consistently as expected.
B marks: Modify your program from Part IIA to incorporate a mutex lock for synchronizing
access to the shared counter. Ensure that each increment operation on the counter is protected by
the mutex. Capture screenshots showing that the issue identified in Part IIA is no longer
present. In your report, explain how the mutex lock solved the problem.
HINTS:
You will need to use the following pthread functions: pthreadcreate
pthreadjoin pthreadmutexinit pthreadmutexdestroy
pthreadmutexlock pthreadmutexunlock
Remember to initialize the mutex before using it and destroy it once it is no longer needed.
Here is how you can declare and use a mutex:
pthreadmutext lock;
pthreadmutexinit&lock, NULL;
pthreadmutexdestroy&lock;
Use this skeleton code for Part II:
Instructions:
Submit one report in PDF format containing the source code for PART I, PART IIA and
PART IIB along with the required execution screenshots as well as the discussion for
PART IIA and PART IIB
Submit the source code for PART I, PART IIA and PART IIB
Ensure to include your name and student ID in the report.
Everything you submit MUST be your OWN work, the use of generative AI tools such as
ChatGPT is strictly prohibited and will result in receiving ZERO in this assignment.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
