✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
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;
}
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!