Message-Id: <200311041411.hA4EBAvB008427@delorie.com> Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Tue, 4 Nov 2003 22:10:58 +0800 From: "zhouxin" To: "cygwin AT cygwin DOT com" Subject: Process hang(100% CPU Usage) when concurrent calling select(),cygwin1.5.5-1 WinXP/Win2000 Mime-Version: 1.0 Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: 7bit hi,all I have reported this problem a week ago.I belive that the test_select.c(see below) is correct.The usage of select() is classical. This testing program initialize a number of threads, each thread create a socket and send UDP packet to UDP server,then wait response by calling select().If select() return 1, call recvfrom() read the response,else if select() timeout goto next loop... If the udp worker's count greater than 18,some thread's select() hang and process take 100% cpu: $uname -a CYGWIN_NT-5.1 zipxing 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown $gcc -o tsel test_select.c $./tsel 15 127.0.0.1 7 --create 15 threads communicate with UDP echo service,no problem $./tsel 20 127.0.0.1 7 --create 20 threads communicate with UDP echo service,100% CPU! I make test_select.c on solaris9 and linux,it seems all ok. Specially, the testing program work fine use cygwin1.dll 1.3.22! Thanks. ========================================================================================= test_select.c ========================================================================================= #include #include #include #include #include #include #include #include #include //Select timeout... int timeout = 5; //Thread count... int tcount = 20; struct sockaddr_in servaddr; //Thread function... void * udpworker(void *ptr) { int sockfd = 0; int tid; char buf[256]; tid = (int)ptr; if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ printf("cannot open socket for udp packet!\n"); exit(1); } while(1){ struct timeval tv; fd_set rfds; //Send request to UDP server... sendto(sockfd, "echo", 4, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); //Wait UDP server response... FD_ZERO(&rfds); FD_SET(sockfd, &rfds); tv.tv_sec = timeout; tv.tv_usec = 0; if(select(sockfd + 1, &rfds, NULL, NULL, &tv) == 1) { recvfrom(sockfd, buf, sizeof(buf), 0, NULL, NULL); printf("thread.%d recive a response...%s\n", tid, buf); } else { printf("thread.%d recvfrom timeout?...\n", tid); } sleep(10); } } //Initial udp client thread pool... void thread_pool_init() { int i; pthread_t thrid; for(i=0; i \n"); exit(0); } tcount = atoi(argv[1]); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(atoi(argv[3])); inet_aton(argv[2], &servaddr.sin_addr); thread_pool_init(); while(1) sleep(1000); } ========================================================================================= -- 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/