Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <semaphore.h>
- sem_t sem_hello_done;
- void* print_hello(void* arg) {
- printf("Hello ");
- sem_post(&sem_hello_done);
- return NULL;
- }
- void* print_world(void* arg) {
- sem_wait(&sem_hello_done);
- printf("World\n");
- return NULL;
- }
- int main() {
- pthread_t t1, t2;
- sem_init(&sem_hello_done, 0, 0);
- pthread_create(&t1, NULL, print_hello, NULL);
- pthread_create(&t2, NULL, print_world, NULL);
- pthread_join(t1, NULL);
- pthread_join(t2, NULL);
- sem_destroy(&sem_hello_done);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement