implemented in both Process and Thread Version asks to write a multi-threaded pr
ID: 642134 • Letter: I
Question
implemented in both Process and Thread Version
asks to write a multi-threaded program to calculate the average, min, and max of of list of numbers. You should also use fork() system calls to create three child processes, each calculating average, min, and max. For process case, because parent and child processes have their own copies of data (even for global data!), it will be necessary to the child to output the results. For thread case, since parent thread and worker threads share global variables, the worker threads will set the values of the global variables, and the parent thread will output the values once the workers have exited.
Explanation / Answer
import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; public class MinMax implements Runnable{ Long min=Long.MAX_VALUE; Long max=Long.MIN_VALUE; int low; int high; Long[] arr; public MinMax(int low, int high, Long[] arr){ this.low = low; this.high=high; this.arr = arr; } @Override public void run() { System.out.println("called run "); if (low-highRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.