logo

Crowdly

When using a semaphore to ensure the child thread runs before the parent execute...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

When using a semaphore to ensure the child thread runs before the parent executes further as in the code snippet below, what value should the semaphore be initialized too (i.e., what should X be)?

sem_t s;

void *child(void *arg) {

printf("child");

sem_post(&s); // signal here: child is done

return NULL;

}

int main(int argc, char *argv[]) {

sem_init(&s, 0, X); // what should X be?

printf("parent: begin");

pthread_t c;

pthread_create(c, NULL, child, NULL);

sem_wait(&s); // wait here for child

printf("parent: end");

return 0;

}

More questions like this

Want instant access to all verified answers on moodle31.upei.ca?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!