public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "zhouxin" <zhoux@harbournetworks.com>
To: cygwin@cygwin.com <cygwin@cygwin.com>
Subject: select() take 100% CPU with cygwin1.5.5-1 in WinXP/Win2000
Date: Fri, 31 Oct 2003 05:59:00 -0000	[thread overview]
Message-ID: <20031031055900.ylnOv3PimGuZaFvriM-KLiIJEwPndtXtqyUt-JUAdHo@z> (raw)

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/

             reply	other threads:[~2003-10-31  5:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-31  5:59 zhouxin [this message]
     [not found] <200310310514.h9V5EMM04538@mx1.redhat.com>
2003-10-31 12:38 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031031055900.ylnOv3PimGuZaFvriM-KLiIJEwPndtXtqyUt-JUAdHo@z \
    --to=zhoux@harbournetworks.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).