Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   problem with sem_wait() please help (http://www.go4expert.com/forums/semwait-help-t17811/)

tina.singh1985 1Jun2009 18:45

problem with sem_wait() please help
 
I am using semaphores and have initialised semaphores called PM_Full and PM_Empty like:

sem_t PM_Empty[MAX_NOOF_BUFFERS];
sem_t PM_Full[MAX_NOOF_BUFFERS];

and

for(i = 0; i < MAX_NOOF_BUFFERS; i++)
{
sem_init(&PM_Empty[i], 0, 1); //will be shared bet. threads,but cannot be shared bet. processes /*PM Buffers as empty*/
sem_init(&PM_Full[i], 0, 0);
Desc_Buffer[i] = NULL;
Valid_Data[i] = 0;
}

Also we have initialised:

short int siBuffer_Select = 0;

And after few value changes finally we have:

sem_wait(&PM_Empty[siBuffer_Select]); /*check for the next buffer is empty or not*/

(here the value of siBuffer_Select is 0)

But this statement does not work, and the code hangs here giving a "segmentation fault" without any description.

Kindly suggest what might be causing the error.

Thanks.


All times are GMT +5.5. The time now is 07:28.