#include #include #include #include #include #include #include #include #define NITER 10000000 sem_t mutex; int count = 0; void * ThreadAdd(void * a) { int i, tmp; while(1){ printf("this is in the thread %d",count); sem_wait(&mutex); } } int main(int argc, char * argv[]) { pthread_t tid1, tid2; sem_init(&mutex, 0, 1); int i=10; if(pthread_create(&tid1, NULL, ThreadAdd, NULL)) { printf("\n ERROR creating thread 1"); exit(1); } if(pthread_join(tid1, NULL)) /* wait for the thread 1 to finish */ { printf("\n ERROR joining thread"); exit(1); } /* here my intention is upto 10 elements loop has to go */ while (i>10){ printf("Enter the id please \n"); scanf("%d",count); i = i-1; sem_post(&mutex); } pthread_exit(NULL); }