NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [Signal handler] Bug or feature ?

On Mon, Oct 15, 2012 at 3:52 AM, BERTRAND Joël
<> wrote:
>         I have tested on 5.1.2 (amd64) and this test program is linked with
> -pthread.

So, your program uses threads?  How many physical CPUs do you have?

You also haven't shown how you install your signal handler.

Also note that the mere fact of linking against libpthread, even if
you do not spawn threads, has implications on the behavior of the
program.  I don't know the details about this though, sorry, but it
wouldn't be surprising if signal handling was slightly different in
this case.

>>> But nanosleep() returns with EINTR error before signal handler is called.
>> On my machine, I can verify that signal handler is called before
>> nanosleep() returns.
>         Not on mine. Even thread id is different between signal handler and
> main program.

Unless I'm very wrong... there is no guarantee about what thread will
receive the signal.  If you have more than one CPU and one thread,
it's possible for one of the CPUs to be running the signal handler and
the other to receive the return from the nanosleep call as EINTR.
Therefore, your code has a race condition.  As with all race
conditions, the fact that a piece of code works in many systems except
in one does not mean that this other system is wrong: it just means
that the original code has a problem.

Julio Merino / @jmmv

Home | Main Index | Thread Index | Old Index