Subject: signal handling oddity with pthreads
To: None <>
From: Matthias Drochner <>
List: current-users
Date: 08/21/2003 14:35:46
This is a multipart MIME message.

Content-Type: text/plain; charset=us-ascii

Hi -
I've tried to track down why many thread using applications
get into a tight loop "if something goes wrong".
The little test program appended shows the same symptoms.
The handler is just not reached, the program gets into an
endless loop catching SIGSEGVs.
When I switch on pthread signal debugging, I get:

(up 0x48600000) switching to 0xbfbc0000 (uc: T 0xbfbff7d0 pc: 8048960)
(recycle 0xbfbc0000) recycled 0x48600000
(up 0x48600000) type 4 LWP 1 ev 1 intr 0
(fi 0x48600000) victim 0 0xbfbc0000(1) nonlockholder
(pt_signal 0x48600000) setting proc sigmask to 00000000
(pthread__kill 0x48600000) target 0xbfbc0000 sig 11 code 6

repeated endlessly.

It seems the signal is "recorded for later delivery" at the
beginning of pthread__kill(); the delivery takes never place.
Looking where the "target" comes from I got discouraged when I
saw the kernel's psendsig() -- perhaps someone can explain
me what that
		if (code)
			le = l;
			li = l;
does? (or better add comments...)

best regards

Content-Type: text/plain ; name="pthhang.c"; charset=us-ascii
Content-Description: pthhang.c
Content-Disposition: attachment; filename="pthhang.c"

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

void *
th(void *dummy)

	return 0;

hdl(int sig)

	fprintf(stderr, "hdl(%d) called\n", sig);
	_exit (1);

	void *osig;
	pthread_t t;
	int res;

	osig = signal(SIGSEGV, hdl);
	if (osig == SIG_ERR)
		err(1, "signal");

	res = pthread_create(&t, 0, th, 0);
	if (res < 0)
		err(1, "pthread_create");

	*(volatile int *)0 = 1;
	exit (0);