This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Signal support under Cygwin
- From: Nicholas Sherlock <n dot sherlock at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 28 Apr 2010 04:25:27 +0000 (UTC)
- Subject: Signal support under Cygwin
- Connect(): No such file or directory
Hi everybody,
I've got some code on Linux which attempts to take periodic samples of my multi-
threaded program to find out what task each thread is working on. For this I am
installing a signal handler for each thread, and periodically sending SIGUSR1 to
each thread I want to check with pthread_kill. This works flawlessly on Linux,
but crashes after a short interval on Cygwin on Windows 7 64-bit. My code is:
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
volatile sig_atomic_t pauses = 0;
static void profiling_sample(int signum) {
(void) signum;
sig_atomic_t old_value = pauses;
++old_value;
/* Might lose concurrent updates to 'pauses' here. Not a big deal. */
pauses = old_value;
}
static void * childthread(void * arg) {
(void) arg;
for (;;) {
sleep(1000);
}
}
#define NUM_THREADS 8
int main(void) {
int i;
pthread_t handles[NUM_THREADS];
struct sigaction action;
action.sa_handler = profiling_sample;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
assert(sigaction(SIGUSR1, &action, NULL) == 0);
for (i = 0; i < NUM_THREADS; i++) {
assert(pthread_create(&handles[i], NULL, childthread, NULL) ==
0);
}
printf("Delivered signals is at least:\n");
for (;;) {
for (i = 0; i < NUM_THREADS; i++) {
int err = pthread_kill(handles[i], SIGUSR1);
if (err) {
fprintf(stderr, "Error from pthread_kill
(%d)\n", err);
exit(-1);
}
}
printf("%d\n", pauses);
}
return EXIT_SUCCESS;
}
My Cygwin is:
$ uname -a
CYGWIN_NT-6.1-WOW64 NickLaptop 1.7.5(0.225/5/3) 2010-04-12 19:07 i686 Cygwin
I am building with:
gcc -std=gnu99 -g3 -W -Wall -o sigtest.exe sigtest.c -lpthread
A typical run on Cygwin shows the "pauses" value counting upwards to about 4000
before the program either hangs without printing anything or causes a segfault
(without a useful looking stacktrace):
(gdb) thread apply all where
Thread 10 (thread 4444.0x179c):
#0 0x1b4bdb2c in ?? ()
#1 0x000003e8 in ?? ()
#2 0x1b4bce64 in ?? ()
#3 0x1b4bcd98 in ?? ()
#4 0x610df995 in pthread::thread_init_wrapper () from /usr/bin/cygwin1.dll
Backtrace stopped: frame did not save the PC
Thread 9 (thread 4444.0x14fc):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000001e4 in ?? ()
#4 0x00000000 in ?? ()
Thread 8 (thread 4444.0x15a4):
#0 0x77bef8dd in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef8dd in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x7748d232 in WriteFile ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x00000124 in ?? ()
#4 0x00000000 in ?? ()
Thread 7 (thread 4444.0x1610):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000000f0 in ?? ()
#4 0x00000000 in ?? ()
Thread 6 (thread 4444.0x144c):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000000f0 in ?? ()
#4 0x00000000 in ?? ()
Thread 5 (thread 4444.0x125c):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000000f0 in ?? ()
#4 0x00000000 in ?? ()
Thread 4 (thread 4444.0x414):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000000f0 in ?? ()
#4 0x00000000 in ?? ()
Thread 3 (thread 4444.0x804):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000001dc in ?? ()
#4 0x00000000 in ?? ()
Thread 2 (thread 4444.0x150c):
#0 0x77bef8a5 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef8a5 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x7748d0c5 in ReadFile () from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x00000120 in ?? ()
#4 0x00000000 in ?? ()
Thread 1 (thread 4444.0xa8):
#0 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#1 0x77bef871 in ntdll!RtlUpdateClonedSRWLock ()
from /cygdrive/c/Windows/system32/ntdll.dll
#2 0x77490816 in WaitForSingleObjectEx ()
from /cygdrive/c/Windows/syswow64/KernelBase.dll
#3 0x000001cc in ?? ()
#4 0x00000000 in ?? ()
#0 0x1b4bdb2c in ?? ()
Is this supposed to work?
Cheers,
Nicholas Sherlock
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple