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: [7 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 90817895797180
The program should print:
Sum =574
Average =82
Max =95
Part II: [8 marks]
A)[4 marks] Write a C program where multiple threads (e.g.,10 threads) each increment a
shared counter by one 100,000 times. Compile and run your program several times (at least 5 runs
are recommended). Provide screenshots of the output from multiple runs. Discuss briefly in your
report why the final counter value is not consistently 1,000,000 as expected.
B)[4 marks]: Modify your program from Part II-A 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 II-A 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: pthread_create (...),
pthread_join(...), pthread_mutex_init(...), pthread_mutex_destroy(...),
pthread_mutex_lock(...), pthread_mutex_unlock (...).
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:
pthread_mutex_t lock;
pthread_mutex_init(&lock, NULL);
pthread_mutex_destroy(&lock);
Use this skeleton code for Part II:
Instructions:
Submit one report in PDF format containing the source code for PART I, PART II-A and
PART II-B along with the required execution screenshots as well as the discussion for
PART II-A and PART II-B.
Submit the source code for PART I, PART II-A and PART II-B.
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.
Part I: [ 7 points | Write a multithreaded

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!