#include #include #include #include sem_t S1,S2; void* P1() { int n=2; do { sem_wait(&S1); printf(" I1 "); sem_post(&S2); n++; }while (n < 10); pthread_exit(0); /* exit */ } void* P2() { int k=1; do { sem_wait(&S2); printf(" I2 "); sem_post(&S1); k++; }while (k < 10); pthread_exit(0); /* exit */ } int main() { sem_init(&S1, 0, 1); sem_init(&S2, 0, 0); pthread_t t1,t2; pthread_create(&t1,NULL,P1,NULL); pthread_create(&t2,NULL,P2,NULL); pthread_join(t1,NULL); pthread_join(t2,NULL); return 0; }