Re: Set thread-local sig_atomic_t in signal handler?

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

 



On Thu, Sep 26, 2013 at 8:34 AM, Ian Pilcher <arequipeno@xxxxxxxxx> wrote:
> Short version:
>
> Can I use a thread-local sig_atomic_t in a signal handler?  I.e.:
>
>   static __thread volatile sig_atomic_t exit_flag = 0;
>
>   static void handler(int signum __attribute__((unused)))
>   {
>       exit_flag = 1;
>   }
>
> (Signals will be sent to specific threads with pthread_kill.)

Yes.  This is one of the few valid uses of volatile in a
multi-threaded program.

That said, a warning: if you put this code in a shared library and
open it with dlopen it may fail in a rather peculiar way.  See
    https://sourceware.org/ml/libc-alpha/2012-06/msg00335.html
I think this behaviour is a bug, but I'm not sure everyone agrees with
me, and in any case it has not been fixed.

Ian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux