Semaphore Usage

J

john

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.
 
R

red floyd

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top