#include #include #include void *thr_main(void *arg); int value; sem_t *sem; int main(int argc, char *argv[]){ pthread_t thrID[3]; int i; value = 1; sem = (sem_t *)malloc( sizeof(sem_t) ); sem_init(sem, 0, 1); for(i=0; i<3; i++) pthread_create(&(thrID[i]), NULL, thr_main, NULL); for(i=0; i<3; i++) pthread_join(thrID[i], NULL); printf("value: %d\n",value); return(0); } void *thr_main(void *arg){ sem_wait(sem); value++; sem_post(sem); }