#include <stdio.h> #include <unistd.h> #include <pthread.h> #include <semaphore.h> sem_t done; void * newthread(void *arg) { sleep(5); printf("newthread\n"); sem_post(&done); return NULL; } int main(int argc, char *argv[]) { pthread_t p; printf("main: begin\n"); sem_init(&done, 0, 0); pthread_create(&p, NULL, newthread, NULL); sem_wait(&done); printf("main: end\n"); return 0; }