Question: For this and the next question, assume the following code successfully compiles and runs on a modern linux machine ( assume any irrelevant details have

For this and the next question, assume the following code successfully compiles and runs on a modern linux machine (assume any irrelevant details have been omitted; also assume that all required header files are included):
int balance =0;
void *mythread(void *arg){
int i;
for (i=0; i<200; i++){
balance++;
}
printf("Balance is %d
", balance);
return NULL;
}
int main(int argc, char *argv[]){
pthread_t p1, p2, p3;
pthread_create(&p1, NULL, mythread, "A");
pthread_join(p1, NULL);
pthread_create(&p2, NULL, mythread, "B");
pthread_join(p2, NULL);
pthread_create(&p3, NULL, mythread, "C");
pthread_join(p3, NULL);
printf("Final Balance is %d
",balance);
}
Assuming none of the functions calls fail, when thread p2 prints "Balance is %d
", what will p2 say is the value of balance ?
Group of answer choices
400
0
600
200

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!