This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Set thread-local sig_atomic_t in signal handler?


On Thu, Sep 26, 2013 at 8:34 AM, Ian Pilcher <arequipeno@gmail.com> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]