* Re: select() take 100% CPU with cygwin1.5.5-1 in WinXP/Win2000
[not found] <200310310514.h9V5EMM04538@mx1.redhat.com>
@ 2003-10-31 12:38 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2003-10-31 12:38 UTC (permalink / raw)
To: cygwin
On Fri, Oct 31, 2003 at 01:14:17PM +0800, zhouxin wrote:
> Cygwin implementation of select() take 100% CPU under multi-thread environment sometimes.
> [...]
> 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);
> }
That's not allowed. What is the select call waiting for? You
didn't bind or connect it.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:cygwin@cygwin.com
Red Hat, Inc.
--
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* select() take 100% CPU with cygwin1.5.5-1 in WinXP/Win2000
@ 2003-10-31 5:59 zhouxin
0 siblings, 0 replies; 2+ messages in thread
From: zhouxin @ 2003-10-31 5:59 UTC (permalink / raw)
To: cygwin
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-10-31 11:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <200310310514.h9V5EMM04538@mx1.redhat.com>
2003-10-31 12:38 ` select() take 100% CPU with cygwin1.5.5-1 in WinXP/Win2000 Corinna Vinschen
2003-10-31 5:59 zhouxin
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).