Question: a concurrent proble ( with multiple threads ) look like this: int counter = 1 0 0 2 ; void * worker ( void *

a concurrent proble (with multiple threads) look like this:
int counter =1002;
void *worker(void *arg)
{counter--;
return NULL;}
int main (int argc, char *argv[]}
{pthread_t p1, p2;
pthread_create{&p1, NULL, worker, NULL);
pthread_create{&p2, NULL, worker, NULL);
pthread_join{&p1, NULL);
pthread_join{&p2, NULL);
printf("%d
", counter);
return 0;
}
Assuming pthread create() and pthread join() all work as expected (i.e., they don't return an error), what are the possible outputs?
Please justify your answers

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!