Question: Execute the pthread_join program several times. Examine the output carefully. You should notice a problem in the implementation. Make sure to follow the logic in

Execute the pthread_join program several times.

Examine the output carefully. You should notice a problem in the implementation. Make sure to follow the logic in main() and to read the comments carefully.

Read the Linux manual page that describes the pthread_join function [URL: https://linux.die.net/man/3/pthread_join] and make sure that you understand the functionality that pthread_join provides and how to call (invoke) this function.

Correct the problem. Look for the // TODO comment and address it (i.e., implement the functionality described in the comment). Hint: The solution requires only one (1) line of code.

Build and run your program and make sure that it works correctly. Expected Output: Your program should produce the following output

#include #include

int count = 0;

// This function implements the code that is // executed by the thread. void* myFunction(void* arg) { int actual_arg = *((int*) arg); for(unsigned int i = 0; i

// This program creates one thread, waits for it // to finish its job and exits. int main() { int rc; pthread_t the_thread; int arg = 1; // Data being passed to the thread

// Create a new thread rc = pthread_create(&the_thread, NULL, myFunction, (void*) &arg);

// Wait for the thread to do its job, then finish

// TODO: Implement a call to pthread_join to ensure // that main() waits for the thread to finish // before continuing. std::cout Thread #1 count 1 Thread #1 count 2 Th read #1 count 3 Th read #1 count 4 Th read #1 count 5 Th read #1 count 6 Th read #1 count 7 Th read #1 count 8 Th read #1 count 9 Th read #1 count 10 Thread #1 done! Final count 10

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 Databases Questions!