Re: Futex wait is not interrupted by signals if no timeout is provided

From: Randy Dunlap
Date: Fri Aug 12 2022 - 21:39:06 EST


[add tglx and mingo]

On 8/12/22 18:14, Elijah Stone wrote:
> I've observed a strange behaviour of futexes that I believe to be a bug.  If a signal is delivered while a futex wait is in progress, the wait will be interrupted, but only if that wait had a timeout.  I expect it to be interrupted regardless of whether a timeout is provided.  The following runnable snippet demonstrates this:
>
> void handler(int) { printf("SIGINT\n"); }
> int main() {
>     signal(SIGINT,handler);
>     int i=2;
>     printf("1\n");
>     syscall(SYS_futex, &i, FUTEX_WAIT, 2, &(struct timespec){.tv_sec=1000});
>     printf("2\n");
>     syscall(SYS_futex, &i, FUTEX_WAIT, 2, NULL);
>     printf("3\n");
> }
>
> Pressing ^C once causes the first wait to terminate, and '2' to be printed. But repeatedly pressing it after that does not allow the program to make progress.

--
~Randy