delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/02/05/21:34:27

X-Spam-Check-By: sourceware.org
Message-ID: <BAY102-F1419989AED32B053AE39DABD0E0@phx.gbl>
X-Sender: ntang99 AT hotmail DOT com
From: "Michael Tang" <ntang99 AT hotmail DOT com>
To: cygwin AT cygwin DOT com
Subject: signal is not delivered to the handler
Date: Mon, 06 Feb 2006 02:34:15 +0000
Mime-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

I ran into a problem with the latest cygwin1.dll (1.5.19-cr-0x5ef):
  1. the main thread creates a udp socket and set up a sigal handler for 
SIGALRM
  2. the main thread creates a new thread T
  3. the main thread calls "recvfrom" on the udp socket" and block there
  4. thread T waits 2 second and sends a signal SIGALRM to the main thread
  5. the main thread fails on "recvfrom" and goes to step 2 again.

The problem is, at the second time, after the new thread T sends the 
SIGALRM, the signal does not trigger the signal handler any more. the 
program hangs.

The program works (never hangs) with an older version of cygwin1.dll 
(1.3.22-dontuse-21).

Ning (Michael) Tang
=================here is the test program output===============
bash-3.00$ ./test
waiting for packet
send ALRM 1
+++++++ Handle signal 14
wait for packet return 4
waiting for packet
send ALRM 1

=================here is the test program===============
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <errno.h>

typedef struct
{
    pthread_t ptid ;
} thr_arg;
void sig_alrm(int signo)
{
   fprintf(stderr, "+++++++ Handle signal %d\n", signo);
}

void *ctrl_listen(void *arg)
{
	thr_arg* parg = (thr_arg*) arg;
	sleep(2);
	fprintf(stderr, "send ALRM 1\n");
	pthread_kill(parg->ptid, SIGALRM);
}


int main()
{
  struct sigaction sigstruct ;
  thr_arg arg;
  pthread_attr_t attr;
    pthread_t tid ;
    char pack_buf[256] ;
    int max_pkt_sz;
  int sock_udp;
  struct sockaddr_in snd_udp_addr;
  int ret;
  int count;

  max_pkt_sz = 256;
  if ((sock_udp=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  {
    perror("socket(AF_INET,SOCK_DGRAM,0):");
    exit(-1);
  }
  bzero((char*)&snd_udp_addr, sizeof(snd_udp_addr));
  snd_udp_addr.sin_family         = AF_INET;
  snd_udp_addr.sin_addr.s_addr    = htonl(INADDR_ANY);
  snd_udp_addr.sin_port           = htons(0);
  if (bind(sock_udp, (struct sockaddr*)&snd_udp_addr,
        sizeof(snd_udp_addr)) < 0)
  {
    perror("bind(sock_udp):");
    exit(-1);
  }

  sigstruct.sa_handler = sig_alrm ;
  sigemptyset(&sigstruct.sa_mask);
  sigstruct.sa_flags = 0 ;
  #ifdef SA_INTERRUPT
    sigstruct.sa_flags |= SA_INTERRUPT ;
  #endif
  sigaction(SIGALRM , &sigstruct,NULL );
  count = 0;
  while(count < 10)
  {
  pthread_attr_init(&attr);
  arg.ptid = pthread_self() ;
  if (pthread_create(&tid,&attr,ctrl_listen, &arg ) != 0 )
  {
    perror("recv_train::pthread_create");
  }

     printf("waiting for packet\n");
     ret = recvfrom(sock_udp, pack_buf, max_pkt_sz, 0, NULL, NULL);
     printf("wait for packet return %d\n", errno);
     count++;
  }
  return 0;
}



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019