This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Mask restart signal handler during cancel handler.
- From: Dwayne Grant McConnell <dgm69 at us dot ibm dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Tue, 5 Oct 2004 16:08:10 -0500 (Central Daylight Time)
- Subject: [PATCH] Mask restart signal handler during cancel handler.
This patch masks the LinuxThreads restart signal during the handling of a
cancel signal.
While running the Java JCK test suite against the IBM JVM 1.3.1 on SLES 9
we found a hang condition because of a bug in LinuxThreads. There was a
case where __pthread_sig_restart (__SIGRTMIN=32) and __pthread_sig_cancel
(__SIGRTMIN+1=33) were being raised at the same time or at least the first
raised before the second was handled. The Linux kernel delivers the lower
numbered one (restart) first in accordance with
The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html
> When multiple unblocked signals, all in the range SIGRTMIN to SIGRTMAX,
> are pending, the behavior shall be as if the implementation delivers the
> pending unblocked signal with the lowest signal number within that
> range. No other ordering of signal delivery is specified.
In our case all threads but one exited. That remaining thread stayed
around. For that thread restart and cancel were posted at the same time
and then restart was delivered first. Because the thread was in a
pthread_cond_timedwait it called siglongjmp and never goes back to the
kernel so the cancel is never delivered. If the cancel had been delivered
it would have caused the thread to exit immediately along with all other
threads because it would have seen that __pthread_exit_reqested was set.
In effect the LinuxThreads library is depending on non-POSIX behavior of
RT signal delivery.
This could be fixed by
1. Changing the numeric order of __pthread_sig_restart and
__pthread_sig_cancel to 33 and 32 respectively and mask all higher
numbered RT signals when running the RT handler
OR
2. Masking the restart signal during the execution of the cancel handler.
This patch implements (2). We have run glibc "make check" and completed
several runs of the JCK with no ill effects.
--
Dwayne Grant McConnell <dgm69@us.ibm.com>
Lotus Notes: Dwayne McConnell/Austin/IBM@IBMUS
2004-10-05 Dwayne Grant McConnell <dgm69@us.ibm.com>
* linuxthreads/pthread.c: Mask restart signal during cancel signal
handler.
diff -apurN libc.orig/linuxthreads/pthread.c libc/linuxthreads/pthread.c
--- libc.orig/linuxthreads/pthread.c 2004-05-03 16:41:39.000000000 -0500
+++ libc/linuxthreads/pthread.c 2004-10-05 15:06:32.127147629 -0500
@@ -560,6 +560,7 @@ static void pthread_initialize(void)
sa.sa_flags = 0;
__libc_sigaction(__pthread_sig_restart, &sa, NULL);
sa.sa_handler = pthread_handle_sigcancel;
+ sigaddset(&sa.sa_mask, __pthread_sig_restart);
// sa.sa_flags = 0;
__libc_sigaction(__pthread_sig_cancel, &sa, NULL);
if (__pthread_sig_debug > 0) {