Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Semaphore Usage

Reply
Thread Tools

Semaphore Usage

 
 
john
Guest
Posts: n/a
 
      04-12-2010
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.
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      04-12-2010
On Apr 12, 5:17*am, john <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Needed : Race condition while removing semaphore(sysvsem semaphore) techi_C C Programming 2 08-10-2006 12:27 PM
Why not work POSIX::RT:Semaphore Dima Perl 0 03-24-2005 01:45 PM
Correct Semaphore Implementation in Java Frank Gerlach Java 34 12-01-2004 01:40 PM
Really (!) correct Semaphore Frank Gerlach Java 6 11-28-2004 06:47 PM
Problem with autoflush on Semaphore-threads for Windows dede Perl 0 07-28-2004 03:48 PM



Advertisments