Async-signal-safe access to __thread variables from dlopen()ed libraries?

Ian Lance Taylor iant@google.com
Wed Oct 2 21:43:00 GMT 2013


On Wed, Oct 2, 2013 at 1:50 PM, Rich Felker <dalias@aerifal.cx> wrote:
>
> It depends on what you mean by "portable". There's absolutely nothing
> useful you can do with a signal handler if writing portable C (since
> there's not even a portable way to expect a signal to happen).

I agree with you, but just to be pedantic I'll note that the functions
raise and signal are both ISO C, and that ISO C permits a signal
handler to assign a value to a variable of type volatile
sig_atomic_t.  So I believe that this is a fully conforming ISO C
program that uses a signal handler.

Ian


#include <signal.h>
#include <stdio.h>

volatile sig_atomic_t signalled;

void handler(int sig) {
  signalled = 1;
}

int main() {
  int f;

  signal(SIGINT, handler);

  f = getchar();
  if (f == 's')
    raise(SIGINT);
  printf("%d\n", signalled);
  return 0;
}



More information about the Libc-alpha mailing list