This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: signal delivery problem (with pthreads)
Hello,
On Fri, 27 Aug 2004 20:17:09 -0400, Christopher Faylor wrote:
> Sorry, but if this is really a problem, you're going to have to provide a
> simple test case which reproduces it. Providing a description of the
> symptoms is not going to do it and neither is unsolicited strace output.
Sorry. My fault.
After this my shame I started exploring the cygwin mail list archive.
At first I found out this:
http://sources.redhat.com/ml/cygwin/2004-04/msg00393.html
And after while I've got (IMHO) a little test source (attached) to
reproduce the problem.
$ gcc-2 -Wall -O2 -W -g -o sig_bug.exe sig_bug.c -lpthread
$ gdb sig_bug.exe
(gdb) r
Starting program: /home/Valery/tmp/sig_bug.exe
new thread start
got signal 30
OK, press any key to exit... <-- there was NO hitting the key
got signal 30
got signal 30 <-- twice!
select was interrupted 1 times
<-- NO "new thread exit" message
Program received signal SIGSEGV, Segmentation fault.
[Switching to thread 58.0x75]
0x00000001 in ?? ()
(gdb) bt
#0 0x00000001 in ?? ()
#1 0x00401080 in sig_hnd ()
#2 0x00401169 in _blah (arg=0x0) at sig_bug.c:45
#3 0x61084329 in cygwin1!__getreent () from /usr/bin/cygwin1.dll
#4 0x610035c4 in getprogname () from /usr/bin/cygwin1.dll
#5 0x6100357a in getprogname () from /usr/bin/cygwin1.dll
As noted in my previous message, 1.5.10-3 and 20040821 are both affected.
1.5.9-1 is not tested. 1.5.7-1 is not affected.
I'll send an additional data only on request (to not be annoying).
And three more things.
First. On strace from 1.5.10-3 (25 May 2004) the sig_bug.exe is crashed
without any of "got signal 30" messages in the program output to stdio.
On strace from 1.5.7-1 (30 Jan 2004) all OK. (just FYI)
Second. I tested various versions of cygwin1.dll by placing it and
sig_bug.exe in one empty directory and just ran sig_bug.exe. There were
no additional processes in the memory that used the cygwin1.dll.
Cygserver.exe was not placed in that directory. The CYGWIN environment
variable was not set.
Third. On 1.5.7-1 the count of "interrupted select" was around 15-30
_thousands_. Is it normal? On 1.5.10-3 and 20040821 always only 1
interruption was shown.
WBR,
Valery
// sig_bug.c - test signal delivery bug with pthreads in cygwin.
// Affected: 1.5.10-3, snapshot 20040821, 1.5.9-1
// Not affected: 1.5.7-1
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#define SIGNAL SIGUSR1
#define STR(s) #s
#define XSTR(s) STR(s)
const char msg[] = "got signal " XSTR(SIGNAL) "\r\n";
static void sig_hnd(int sig)
{
write(1, msg, sizeof(msg) - 1);
}
static void my_sleep(int sec)
{
struct timeval tv;
time_t curtime, endtime;
int cnt = 0;
endtime = time(NULL) + sec;
while ((curtime = time(NULL)) < endtime) {
tv.tv_sec = endtime - curtime;
tv.tv_usec = 0;
if (select(0, NULL, NULL, NULL, &tv) == 0 || errno != EINTR)
break;
cnt++;
}
if (cnt)
printf("select was interrupted %d times\n", cnt);
}
static void *_blah(void *arg)
{
printf("new thread start\n");
my_sleep(3);
printf("new thread exit\n");
return NULL;
}
int main()
{
pthread_t blah;
signal(SIGNAL, sig_hnd);
if (pthread_create(&blah, NULL, _blah, NULL)!=0)
return perror("CREATE"), 1;
sleep(1);
if (pthread_kill(blah, SIGNAL) != 0)
return perror("KILL"), 1;
sleep(1);
if (pthread_kill(blah, SIGNAL) != 0)
return perror("KILL"), 1;
printf("OK, press any key to exit...\n");
getchar();
return 0;
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/