For the following multithreaded program, use system level scope for thread scheduling. Submit your program and screenshot of output in a single word/pdf file.
Write a multithreaded program (USING C 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
The variables representing the average, minimum, and maximum values will be stored globally. The worker threads will set these values, and the parent thread will output the values once the workers have exited. (We could obviously expand this program by creating additional threads that determine other statistical values, such as median and standard deviation.)
Code :
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
int *list,list_size;
int maximum,minimum,average;
void *maximumValue(void *var);
void *minimumValue(void *var);
void *averageValue(void *var);
int main(int argc,char* argv[])
{
if (argc==1) printf("Please enter an array of
numbers\n");
else if (argc>2)
{
pthread_attr_t
custom_sched_attr;
pthread_attr_init(&custom_sched_attr);
// use system level scope for thread
scheduling
pthread_attr_setscope(&custom_sched_attr,
PTHREAD_SCOPE_SYSTEM);
pthread_t
thread_max,thread_min,thread_avg;
list_size = argc-1;
list = (int *)
malloc((list_size)*sizeof(int));
for (int i=0;i<list_size;i++)
list[i] = atoi(argv[i+1]);
//creation of
threads
pthread_create(&thread_max,
&custom_sched_attr, maximumValue,NULL);
pthread_create(&thread_min,
&custom_sched_attr, minimumValue,NULL);
pthread_create(&thread_avg,
&custom_sched_attr, averageValue,NULL);
pthread_join(thread_max,
NULL);
pthread_join(thread_min,
NULL);
pthread_join(thread_avg,
NULL);
//all threads finish
execution and then we print the values
printf("The average value is
%d\nThe minimum value is %d\nThe maximum value is
%d",average,minimum,maximum);
exit(0);
}
}
void *maximumValue(void *var)
{
maximum = list[0];
for (int i=1;i<list_size;i++) if
(maximum<list[i]) maximum = list[i];
return NULL;
}
void *minimumValue(void *var)
{
minimum = list[0];
for (int i=1;i<list_size;i++) if
(minimum>list[i]) minimum = list[i];
return NULL;
}
void *averageValue(void *var)
{
average = 0;
for (int i=0;i<list_size;i++) average +=
list[i];
average=average/list_size;
return NULL;
}
Output :-

For the following multithreaded program, use system level scope for thread scheduling. Submit your program and...
Write in C Program.... Write a multi-threaded 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...
Do the following project: Following is the file to be programmed
in Linux kernel. Run this program. Include the screenshot of the
results.
Multi threaded Sorting Application
Write a multithreaded sorting program that works as follows: A
list of integers is divided into two smaller lists of equal size.
Two separate threads (which we will term sorting threads) sort each
sub list using a sorting algorithm of your choice. The two sub
lists are then merged by a third thread—a...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
Write a program to read the contents of data.txt file, and determine the smallest value (min), largest value (max), and the average value (ave). The minimum, maximum, and average values must be calculated in the function calc(). Remember to declare the stdlib.h library, so that you can use the atof function, which will convert the number in the text file into float number. Also, remember to check if there is an error opening the file or not. If there is...
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...
The picture is given in a PPM file and your program should put
the converted one into another PPM file.
•Use argv[1] for the given file and argv[2] for the converted
file.In addition, you can use a temporary file called
tmp.ppm.
•The number of rows and columns are not fixed numbers.
•The converted file should also follow the PPM format with the
above simplification, and can be converted subsequently.
•Read the pixel matrix into a buffer.
•For each row i(...
Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program must allow for the teacher to either enter a predetermined number of scores (e.g. 10 exam scores), to keep allowing them to enter in scores until they are finished. You will need to convert these scores to a percentage then store these in a list. You will perform some calculations on these results and also display the contents of the list (percentage values) back...
Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...
The purpose of this lab is to manipulate an array of integers. The assignment is to write a program that: 1. Declares an array of integers of some maximum size 20. 2. Implements the following functions: ü A function that prompts the user to initialize the array with up to 20 non-negative whole numbers and mark the end of the input with a negative number. The entire array does not need to be initialized. The user may enter only as...