Re: [algogeeks] Pthread and Semaphore

2012-11-26 Thread Jagannath Prasad Das
Thanks all for the response. I thought of constructing a conditional wait using semaphores as follows: //global flag = 0. void *text(void *arg) { int n = *(int*)arg; while(flag != n) { sem_wait(mutex); internal_flag = 1; } if(internal_flag) sem_post(mutex);

[algogeeks] Pthread and Semaphore

2012-11-25 Thread jagannath
Folks, I have one pthread question.I know that its not the right place but i thought this is the right place to post this. Code snippet: #include stdlib.h #include stdio.h #include unistd.h /* defines _POSIX_THREADS if pthreads are available */ #ifdef _POSIX_THREADS # include pthread.h

Re: [algogeeks] Pthread and Semaphore

2012-11-25 Thread naveen bansal
Hi, As you are creating a thread and soon after you are joining for it. { pthread_create(tid[i], NULL, text, (void*)code[i]); pthread_join(tid[i],NULL); } then all the threads wont run in parallel. Like thread[1] will get started and then main thread will wait for it. Do you really want to do

Re: [algogeeks] Pthread and Semaphore

2012-11-25 Thread vIGNESH v
You can use mutex instead of semaphores if you need to execute only one case at a time. FROM, V.VIGNESH. M.Sc Theoretical Computer Science. PSG College of Technology On 25 November 2012 22:37, jagannath jpdasi...@gmail.com wrote: Folks, I have one pthread question.I know that its not the

Re: [algogeeks] Pthread and Semaphore

2012-11-25 Thread Jagannath Prasad Das
@Naveen: I didn't understand your point . Can you please throw more light on join operation On Sun, Nov 25, 2012 at 10:47 PM, vIGNESH v v.v.07121...@gmail.com wrote: You can use mutex instead of semaphores if you need to execute only one case at a time. FROM, V.VIGNESH. M.Sc Theoretical

Re: [algogeeks] Pthread and Semaphore

2012-11-25 Thread Sumit Agarwal
According to your code snippet, all threads would execute one by one serially i.e. first thread would be created, would execute text routine and terminate; then second thread would be created, would execute text routine and terminate and so on. Hence, multiple threads are not running in parallel.