#include #include #include #include sem_t S1,S2; void* P1() { sem_wait(&S1); printf(" A "); sem_post(&S2); pthread_exit(0); /* exit */ } void* P2() { printf(" B "); sem_post(&S1); pthread_exit(0); /* exit */ } void* P3() { sem_wait(&S2); printf(" C "); pthread_exit(0); /* exit */ } int main() { sem_init(&S1, 0, 0); sem_init(&S2, 0, 0); pthread_t t1,t2,t3; pthread_create(&t1,NULL,P1,NULL); pthread_create(&t2,NULL,P2,NULL); pthread_create(&t3,NULL,P3,NULL); pthread_join(t1,NULL); pthread_join(t2,NULL); pthread_join(t3,NULL); printf(" \n "); return 0; }