forked from remzi-arpacidusseau/ostep-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendezvous.c
36 lines (30 loc) · 835 Bytes
/
rendezvous.c
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
34
35
#include <stdio.h>
#include <unistd.h>
#include "common_threads.h"
// If done correctly, each child should print their "before" message
// before either prints their "after" message. Test by adding sleep(1)
// calls in various locations.
sem_t s1, s2;
void *child_1(void *arg) {
printf("child 1: before\n");
// what goes here?
printf("child 1: after\n");
return NULL;
}
void *child_2(void *arg) {
printf("child 2: before\n");
// what goes here?
printf("child 2: after\n");
return NULL;
}
int main(int argc, char *argv[]) {
pthread_t p1, p2;
printf("parent: begin\n");
// init semaphores here
Pthread_create(&p1, NULL, child_1, NULL);
Pthread_create(&p2, NULL, child_2, NULL);
Pthread_join(p1, NULL);
Pthread_join(p2, NULL);
printf("parent: end\n");
return 0;
}