Signals may be lost during setjmp or longjmp

Christian Franke Christian.Franke@t-online.de
Fri Nov 22 14:22:36 GMT 2024


The command 'stress-ng --longjmp ... -t 1' occasionally fails to 
terminate because some child process does not receive the SIGALRM 
indicating timeout.

Testcase (attached):

$ g++ -O2 -o longjmpsigs longjmpsigs.cc

$ ./longjmpsigs
[^C]
INT   1
[^C]
INT   2
...
[^C]
INT   21
[^C]
[^C]
INT   22
...

The following run in a second window may not stop the process due to few 
lost signals:

for i in {1..100}; do
   echo $i; killall -INT longjmpsigs || break; sleep 1
done

The problem does not occur if a regular loop is used instead of 
setjmp/longjmp.

Reproducible also with current cygwin1.dll 26144e40.

-- 
Regards,
Christian

-------------- next part --------------
#include <setjmp.h>
#include <stdio.h>
#include <signal.h>
#include <atomic>

static volatile std::atomic_int sigcnt;

static void sigfunc(int) { sigcnt++; }

int main()
{
  volatile int prev = 0;
  signal(SIGINT, sigfunc);

  jmp_buf jb; setjmp(jb); // loop:

  volatile int cnt = sigcnt;
  if (cnt > prev) {
    printf("INT %3d\n", cnt);
    if (cnt >= 100)
      return 0;
    prev = cnt;
  }

  longjmp(jb, 1); // goto loop;
}


More information about the Cygwin mailing list