Computers and Technology

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);
}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:10, AleciaCassidy
Consider a direct-mapped cache with 216 words in main memory. the cache has 16 blocks of 8 words each. it is a word-addressable computer (rather than a byte-addressable computer which we normally discuss). (a) how many blocks of main memory are there? (b) what is the format of a memory address as seen by the cache, that is, what are the sizes of the tag, cache block, and block offset fields (if they apply)? (c) to which cache block will the memory reference db6316 map?
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, janny48
How often does colleges update the cost of attendance on their website? . a)every two years b) every four years c) every year d) every semester
Answers: 1
image
Computers and Technology, 24.06.2019 11:20, tiffanibell71
Colby works as a shipping clerk for a major package delivery service. some of his daily tasks include tracking shipments and entering orders. which aspect of the information technology cluster would he most likely be trained in? a. networkingb. databasesc. hardwared. software
Answers: 2
image
Computers and Technology, 24.06.2019 20:20, isaiahromero15
Write python code that prompts the user to enter his or her favorite color and assigns the user’s input to a variable named color.
Answers: 1
Do you know the correct answer?
Modify this code to use multiple threads with the same data
1. Modify the main function to imp...

Questions in other subjects: