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]

signal is not delivered to the handler


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/


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