Mail Archives: cygwin/2003/10/31/00:14:32
Cygwin implementation of select() take 100% CPU under multi-thread environment sometimes.
I have wrote a short test program(see below test_select.c) that reproduces the bug:
#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 5 (5 threads, no problem)
^C
#./tsel 17(17 threads, no problem)
^C
#./tsel 18(18 threads, tsel take 100% cpu!!! It seems that 18 is a critical value.)
and I compile and execute test_select.c in solaris9,all ok...
Is this a bug of Cygwin implementation of select()?
help,thanks!
test_select.c
___________________________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/socket.h>
//Select timeout...
int timeout = 30;
//Thread count...
int tcount = 20;
//Thread function...
void *
tp(void *ptr) {
int sockfd = 0;
int tid;
tid = (int)ptr;
if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
fprintf(stderr, "cannot open socket for udp packet!\n");
exit(1);
}
while(1){
struct timeval tv;
fd_set fds;
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
printf("select the socket_fd : %d, thread_id is : %d\n",
sockfd, tid);
select(sockfd + 1, &fds, NULL, NULL, &tv);
}
}
//Initial thread pool...
void
thread_pool_init() {
int i;
pthread_t thrid;
for(i=0; i<tcount; i++)
pthread_create(&thrid, NULL, tp, (void *)i);
}
int
main(int argc, char *argv[])
{
if(argc>1)
tcount = atoi(argv[1]);
thread_pool_init();
while(1){
sleep(10000);
}
}
_____________________________________________________________________________________
--
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 -