This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 1.7.15-1: pthread_cancel and pthread_kill not working as expected

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

#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) {

  fprintf(stderr, "Thread %i executes signal handler (%p)\n", tnum, self);

static void install_handler(void) {
  struct sigaction act;
  act.sa_handler = &sigusr1_handler;
  act.sa_flags = 0;

  // Install signal handler
  if (sigaction(SIGUSR1, &act, NULL) != 0) {
    fprintf(stderr, "Can't set signal handler: %s\n", strerror(errno));

  // Make sure SIGUSR1 is not blocked
  sigset_t 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;


  // 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;

  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));
    fprintf(stderr, "\n");

  return 0;

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]