Mail Archives: cygwin/2012/07/11/08:36:38
--------------020107030407000406050501
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
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
--------------020107030407000406050501
Content-Type: text/x-csrc;
name="testcase_signal.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="testcase_signal.c"
#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;
}
--------------020107030407000406050501
Content-Type: text/plain; charset=us-ascii
--
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
--------------020107030407000406050501--
- Raw text -