This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: 1.7.15-1: pthread_cancel and pthread_kill not working as expected
- From: Otto Meta <otto dot meta at sister-shadow dot de>
- To: cygwin at cygwin dot com
- Date: Wed, 11 Jul 2012 14:22:31 +0200
- Subject: Re: 1.7.15-1: pthread_cancel and pthread_kill not working as expected
- References: <4FAAAE25.40204@sister-shadow.de> <4FB62304.2000100@sister-shadow.de> <CA+sc5mkqAoFoO=Jh19WMFe7FDq0337nz5r3-o6ogvGMvt3qPYw@mail.gmail.com> <4FBA1846.6020005@sister-shadow.de> <20120521104717.GC7763@calimero.vinschen.de> <4FBA38A5.5030408@sister-shadow.de> <20120522110238.GC15843@calimero.vinschen.de>
On 2012-05-22 13:02, Corinna Vinschen wrote:
[...]
>> Testcase signal/kill:
>> Signals may or may not reach the correct thread with 1.7.12-1 and newer.
>
> Confirmed. I think the reason is that we only have a single event to
> signal that a POSIX signal arrived instead of a per-thread event, but
> I'm not sure. This is cgf's domain so I leave it at that for now.
Is this problem still in the queue? The newest snapshot yields the
same results as before.
$ uname -srv
CYGWIN_NT-6.1-WOW64 1.7.16s(0.261/5/3) 20120708 00:52:15
I attached a slightly simpler version of the testcase.
Test output:
Sending SIGUSR1 to thread 2
Thread 0 encountered an error: Interrupted system call
Sending SIGUSR1 to thread 1
Thread 1 executes signal handler
Thread 1 encountered an error: Interrupted system call
Sending SIGUSR1 to thread 0
Thread 2 executes signal handler
Thread 2 encountered an error: Interrupted system call
Otto
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
pthread_t tids[3];
static void* simplethread(void *arg) {
int *intptr = (int*)arg;
pthread_t self = pthread_self();
fprintf(stderr, "Thread %i starting (%p)\n", *intptr, self);
while (1) {
if (pause() != 0) {
fprintf(stderr, "Thread %i encountered an error: %s (%p)\n",
*intptr, strerror(errno), self);
} else {
fprintf(stderr, "Thread %i woke up just fine\n", *intptr);
}
}
return NULL;
}
static void sigusr1_handler(int signal __attribute((unused))) {
pthread_t self = pthread_self();
// Search for thread number
int tnum = 0;
while (tnum < 3) {
if (tids[tnum] == self) {
break;
}
tnum++;
}
fprintf(stderr, "Thread %i executes signal handler (%p)\n", tnum, self);
}
static void install_handler(void) {
struct sigaction act;
act.sa_handler = &sigusr1_handler;
sigemptyset(&(act.sa_mask));
act.sa_flags = 0;
// Install signal handler
if (sigaction(SIGUSR1, &act, NULL) != 0) {
fprintf(stderr, "Can't set signal handler: %s\n", strerror(errno));
exit(1);
}
// Make sure SIGUSR1 is not blocked
sigset_t sset;
sigemptyset(&sset);
sigaddset(&sset, SIGUSR1);
if (sigprocmask(SIG_UNBLOCK, &sset, NULL) != 0) {
fprintf(stderr, "Can't unblock SIGUSR1: %s\n", strerror(errno));
}
}
int main() {
fprintf(stderr, "Testing pthread_kill()\n\n");
int i;
int result;
install_handler();
// Create threads
for (i=0; i<3; i++) {
int *intptr = (int*)malloc(sizeof(int));
*intptr = i;
result = pthread_create(tids+i, NULL, &simplethread, intptr);
if (result != 0) {
fprintf(stderr, "Can't create thread: %s\n", strerror(result));
return 1;
}
}
sleep(1);
install_handler();
fprintf(stderr, "\n");
// Poke all threads
for (i=2; i>=0; i--) {
fprintf(stderr, "Sending SIGUSR1 to thread %i (%p)\n", i, tids[i]);
result = pthread_kill(tids[i], SIGUSR1);
if (result != 0) {
fprintf(stderr, "Error during pthread_kill: %s\n", strerror(result));
}
sleep(1);
fprintf(stderr, "\n");
}
return 0;
}
--
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