Question: The following code would not perform as expected due to the fact that each thread has its own dedicated stack, and is thus inaccessible to

The following code would not perform as expected due to the fact that each thread has its own dedicated stack, and is thus inaccessible to other threads. Assume threadfunc was just invoked as a result of a call to pthread_create().
static struct data * dataptr;
void * threadfunc(void * arg){
pthread_t workthr;
void * workprod;
struct data * indata =(struct data *)arg;
struct data mydata =*indata;
// modify "mydata" here...
dataptr = &mydata;
pthread_create(&workthr, NULL, workthrfunc, NULL);
pthread_join(workthr, &workprod);
// process "workprod" here...
}

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