This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: Async-signal-safe access to __thread variables from dlopen()ed libraries?


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]