problem with sem_wait() please help

Discussion in 'C' started by tina.singh1985, Jun 1, 2009.

  1. tina.singh1985

    tina.singh1985 New Member

    Joined:
    Jun 1, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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, 0, 1); //will be shared bet. threads,but cannot be shared bet. processes /*PM Buffers as empty*/
    sem_init(&PM_Full, 0, 0);
    Desc_Buffer = NULL;
    Valid_Data = 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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice