Date: Sun, 3 Feb 2002 11:19:39 +0300 (MSK) From: Maxim Konovalov <maxim@macomnet.ru> To: David Malone <dwmalone@maths.tcd.ie> Cc: roam@FreeBSD.ORG, <yxpan@yahoo.com>, <freebsd-bugs@FreeBSD.ORG> Subject: Re: i386/34536: accept() blocks other threads Message-ID: <20020203110107.P50975-100000@news1.macomnet.ru> In-Reply-To: <20020203011345.G59736-100000@news1.macomnet.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
By the way, I cannot reproduce the problem. I tried on -current and old 4.3 a code below, it works as expected: /* This is just a test program * Compile: * cc -o thread thread.c -pthread * Test: * ./thread 90 * telnet localhost 90 */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <errno.h> #include <pthread.h> #include <stdio.h> #include <string.h> #include <unistd.h> void * bg(void *a) { for (;;) { printf("+"); fflush(NULL); sleep(1); } } void * srv(void *arg) { char buff[100]; printf("Begin to read\n"); count=read((int)arg, buff, 10); close((int)arg); printf("Begin to exit\n"); } main(int argc, char *argv[]){ int sock, newsock, length, port,pid, i; struct sockaddr_in addr, daddr; pthread_t ptid; pthread_attr_t tattr; if(argc==1) { printf("Usage:\n %s Port\n", argv[0]); exit(1); } port=atoi(argv[1]); if(port==0){ printf("Illegal Port:%s\n", argv[1]); exit(1); } sock=socket(AF_INET, SOCK_STREAM,0); if(sock < 0){ perror("Opening stream socket"); exit(1); } bzero(&addr, sizeof(addr)); addr.sin_family=AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(port); if(bind(sock, (struct sockaddr *)&addr, sizeof addr) == -1){ perror("Binding stream socket"); exit(1); }; bzero(&addr, sizeof(addr)); i = sizeof(addr); if(getsockname(sock, (struct sockaddr *)&addr, &i) < 0){ perror("getsockname"); exit(1); } if(listen(sock, 5) == -1){ perror("Listening stream socket"); exit(1); }; pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); pthread_create(&ptid, NULL, bg, NULL); while((newsock=accept(sock, (struct sockaddr *)&daddr, (length=sizeof daddr, &length))) != -1){ printf("Main Thread is going to start a new thread\n"); if(pthread_create(&ptid, &tattr, srv, (void *)newsock)){ printf("pthread_create() failed\n"); close(newsock); } } /* never reached */ close(sock); } Here is an output: [maxim@try maxim]$ ./thread 2000 +++++Main Thread is going to start a new thread Begin to read +++Main Thread is going to start a new thread Begin to read +++Begin to exit +++Begin to exit +^C [maxim@try maxim]$ So all four threads are sheduled. I guess there may by libc/libc_r interoperability somewhere. -- Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020203110107.P50975-100000>