forked from remzi-arpacidusseau/ostep-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.c
More file actions
33 lines (27 loc) · 592 Bytes
/
join.c
File metadata and controls
33 lines (27 loc) · 592 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include "common.h"
#include "common_threads.h"
#ifdef linux
#include <semaphore.h>
#elif __APPLE__
#include "zemaphore.h"
#endif
sem_t s;
void *child(void *arg) {
sleep(2);
printf("child\n");
Sem_post(&s); // signal here: child is done
return NULL;
}
int main(int argc, char *argv[]) {
Sem_init(&s, 0);
printf("parent: begin\n");
pthread_t c;
Pthread_create(&c, NULL, child, NULL);
Sem_wait(&s); // wait here for child
printf("parent: end\n");
return 0;
}