Re: POSIX semaphores: sem_wait fails when run in debugger?

From: Kasper Dupont (remove.invalid_at_nospam.lir.dk.invalid)
Date: 08/10/04


Date: Tue, 10 Aug 2004 06:34:26 +0200

Joe Knapka wrote:
>
> Anyway, it does seem that gdb is sending a signal that causes
> sem_wait() to be interrupted. What is the correct way to deal with
> that eventuality? (A pointer to a relevant manpage or FAQ would
> suffice.)

I guess you could just add a loop to retry the call until
it does not produce an -EINTR. But I would have expected
the kernel to do that, so I don't understand exactly why
you need to do that yourself.

I think something like this (untested) would work:
int sem_wait_rep(sem_t * sem)
{
   int r;
   do {
      r=sem_wait(sem);
   } while ((r==-1) && (errno=EINTR));
   return r;
}

-- 
Kasper Dupont -- der bruger for meget tid paa usenet.
Design #413859655
It's a computer monitor! It is great for hammering in nails!


Relevant Pages