Semaphore Usage

Discussion in 'C++' started by john, Apr 12, 2010.

  1. john

    john Guest

    Hi,

    firstly not sure if this is the right group as obviously semaphores
    implementation seems to be OS dependent but I couldn't find a unix
    programming group?

    Anyway, just in case someone can help my error is like so. I have two
    processes running - one process created a semaphore whilst the other
    just needs to look at it and perform an operation based on it being set.
    Here is a rough copy of the code:


    Process 1:

    semget(key, 1, IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH)
    semctl(m_nSemID, 0, SETALL, arg)

    struct sembuf stSemBuf[1];
    stSemBuf[0].sem_num = 0;
    stSemBuf[0].sem_op = 1;

    while(bLoop)
    {

    if(semop(m_nSemID, stSemBuf, 1)!=0)
    {
    .....error
    }

    }


    Process 2:

    struct sembuf stSemBuf[1];
    stSemBuf[0].sem_num = 0;
    stSemBuf[0].sem_op = -1;

    while(bLoop)
    {
    if(semop(nSemKey, stSemBuf, 1)==0)
    {
    ...do something
    }
    }

    Everything seems to run fine for about 5 minutes then I get errors in
    process 1 semop with ERANGE. I had a read of the man pages but can't
    figure out why I would get this error as I am not setting the SEM_UNDO flag.

    Can anyway provide any insight into my problem or point me in the right
    direction to sorting it out myself?

    Cheers,

    John.
    john, Apr 12, 2010
    #1
    1. Advertising

  2. john

    red floyd Guest

    On Apr 12, 5:17 am, john <> wrote:
    > Hi,
    >
    > firstly not sure if this is the right group as obviously semaphores
    > implementation seems to be OS dependent but I couldn't find a unix
    > programming group?
    >


    I wanted some meat, but I couldn't find the way to the butcher shop,
    so I went to the greengrocer instead.

    Try comp.unix.programmer
    red floyd, Apr 12, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dede
    Replies:
    0
    Views:
    574
  2. Dima
    Replies:
    0
    Views:
    2,228
  3. Frank Gerlach
    Replies:
    34
    Views:
    15,214
  4. Frank Gerlach

    Really (!) correct Semaphore

    Frank Gerlach, Nov 27, 2004, in forum: Java
    Replies:
    6
    Views:
    399
    Chris Smith
    Nov 28, 2004
  5. techi_C
    Replies:
    2
    Views:
    1,394
    Richard Bos
    Aug 10, 2006
Loading...

Share This Page