Question: C++ Code: For the C++ code below: #include #include using namespace std; void *PrintHello(void *arg) { int actual_arg = *((int*) arg); cout int main() {
C++ Code:
For the C++ code below:
#include
using namespace std;
void *PrintHello(void *arg) { int actual_arg = *((int*) arg); cout
int main() { pthread_t id; int rc; cout
int t = 23; rc = pthread_create(&id, NULL, PrintHello, (void*) &t);
if (rc){ cout
pthread_exit(0); }



Main Code:
#include
using namespace std;
// This function shows the skeleton that pthread // functions must adhere to. // Copy this skeleton for any pthread function // you need to define. // In the copy, modify the name of the function // and the function body as needed. void *routineName(void *arg) { // TODO: Add code that implements // the thread's functionality cout
int main() { // id is used to store a unique thread identifier, // returned by the call to create a new POSIX thread pthread_t id; // rc is used to store the code returned by the // call to create a new POSIX thread. The value is // zero (0) if the call succeeds. int rc; // TODO: Add code to perform any needed initialization // or to process user input
// Create thread(s) // TODO: Modify according to assignment requirements rc = pthread_create(&id, NULL, routineName, NULL);
if (rc){ cout
// NOTE: Using exit here will immediately end execution of all threads pthread_exit(0); }
Take the pthread_test 3.cpp program and modify the main function, instead of pre-specifying/hard-coding the integer to be passed to the pthread function PrintHello, ask the user to enter an integer and pass that integer to the pthread function. Build and run your program and make sure that it works correctly Your output should be similar to the following In main: creating thread Enter a number: 52 Hello World from thread with arg: 52! Take the pthread_test 3.cpp program and modify the main function, instead of pre-specifying/hard-coding the integer to be passed to the pthread function PrintHello, ask the user to enter an integer and pass that integer to the pthread function. Build and run your program and make sure that it works correctly Your output should be similar to the following In main: creating thread Enter a number: 52 Hello World from thread with arg: 52
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
