2008. 1. 22. 16:34
pthread 예제 삽질예방/pthread2008. 1. 22. 16:34
#include <STDIO.H> #include <PTHREAD.H> #include <SEMAPHORE.H> void* PrintHelp(void* nothing); void* PrintHelp2(void* nothing); sem_t sem; int main(void) { pthread_t th1, th2; void* arg; sem_init(&sem, 0, 0); pthread_create(&th1, NULL, PrintHelp, arg); pthread_create(&th2, NULL, PrintHelp2, arg); pthread_join(th2, NULL); pthread_join(th1, NULL); sem_destroy(&sem); return 0; } void* PrintHelp(void* nothing) { sem_wait(&sem); printf("print help...\n"); return 0; } void* PrintHelp2(void* nothing) { getchar(); printf("Print2Ended\n"); sem_post(&sem); return 0; }