subject

Modify this code to use multiple threads with the same data
1. Modify the main function to implement a loop that reads 10 integers from the console (user input) and stores these numbers in a one-dimensional (1D) array (this code will go right after the comment that says "Add code to perform any needed initialization or to process user input"). You should use a global array for this.
2. Implement a separate pthread function function for each one of the following operations:
A. Count and print out how many of the entered numbers are negative. This function must be named countNegatives
B. Calculate and print the average value of all the numbers entered. This function must be named average
C. Print the numbers in reverse order from the order in which they were entered. This function must be named reverse
3.Modify the main function to create one pthread for each one of the functions that you implemented in (3) above (this code will go between the comment that says "TODO: Modify according to assignment requirements" and the "if (rc)" check).
Compile your program and run it several times. If the output of your program is garbled, you may need to add a small delay in between creating the next thread.
#include
#include
using namespace std;
void *routineName(void *arg)
{
// TODO: Add code that implements
// the thread's functionality
cout << "Thread is running..." << endl;
return 0;
}
int main()
{
pthread_t id;
int rc;
int ints;
for(int x; x<10; x++)
{
cout << "Enter Integer: " < cin >>
}
rc = pthread_create(&id, NULL, routineName, NULL);
if (rc){
cout << "ERROR; return code from pthread_create() is " << rc << endl;
return -1;
}
pthread_exit(0);
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:40
State the parts of a variable declaration?
Answers: 2
question
Computers and Technology, 22.06.2019 14:10
Dean wants a quick way to look up staff members by their staff id. in cell q3, nest the existing vlookup function in an iferror function. if the vlookup function returns an error result, the text “invalid staff id” should be displayed by the formula. (hint: you can test that this formula is working by changing the value in cell q2 to 0, but remember to set the value of cell q2 back to 1036 when the testing is complete.)
Answers: 3
question
Computers and Technology, 23.06.2019 06:30
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
question
Computers and Technology, 23.06.2019 10:50
The volume v and paper surface area a of a conical paper cup are given by where r is the radius of the base of the cone and h is the height of the cone. a. by eliminating h, obtain the expression for a as a function of r and v. b. create a user-de ned function that accepts r as the only argument and computes a for a given value of v. declare v to be global within the function. c. for v ! 10 in.3 , use the function with the fminbnd function to compute the value of r that minimizes the area a. what is the corresponding value of the height h? investigate the sensitivity of the solution by plotting v versus r. how much can r vary about its optimal value before the area increases 10 percent above its minimum value?
Answers: 1
You know the right answer?
Modify this code to use multiple threads with the same data
1. Modify the main function to imp...
Questions
question
English, 29.09.2019 22:10
question
Mathematics, 29.09.2019 22:10
Questions on the website: 13722367