From: Otto Meta <otto.meta@sister-shadow.de>
To: cygwin@cygwin.com
Subject: Re: 1.7.15-1: pthread_cancel and pthread_kill not working as expected
Date: Wed, 11 Jul 2012 12:36:00 -0000 [thread overview]
Message-ID: <4FFD7007.4080701@sister-shadow.de> (raw)
In-Reply-To: <20120522110238.GC15843@calimero.vinschen.de>
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
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
[-- Attachment #2: testcase_signal.c --]
[-- Type: text/x-csrc, Size: 2227 bytes --]
#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;
}
[-- Attachment #3: Type: text/plain, Size: 218 bytes --]
--
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
prev parent reply other threads:[~2012-07-11 12:36 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 17:50 1.7.14-2: " Otto Meta
2012-05-18 10:23 ` 1.7.15-1: " Otto Meta
2012-05-18 11:43 ` Earnie Boyd
2012-05-21 10:26 ` Otto Meta
2012-05-21 10:47 ` Corinna Vinschen
2012-05-21 12:44 ` Otto Meta
2012-05-22 11:03 ` Corinna Vinschen
2012-05-22 13:26 ` Otto Meta
2012-05-23 8:53 ` Corinna Vinschen
2012-05-23 16:27 ` Corinna Vinschen
2012-05-23 17:24 ` Corinna Vinschen
2012-05-23 17:44 ` David Rothenberger
2012-05-23 18:26 ` Corinna Vinschen
2012-05-23 20:26 ` Corinna Vinschen
2012-05-24 5:52 ` David Rothenberger
2012-05-24 7:07 ` Corinna Vinschen
2012-05-24 10:36 ` Otto Meta
2012-05-24 10:59 ` Otto Meta
2012-05-24 11:21 ` Corinna Vinschen
2012-05-24 15:37 ` Otto Meta
2012-05-24 16:14 ` Corinna Vinschen
2012-05-24 19:15 ` Otto Meta
2012-05-25 10:04 ` Corinna Vinschen
2012-07-11 12:36 ` Otto Meta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FFD7007.4080701@sister-shadow.de \
--to=otto.meta@sister-shadow.de \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).