Subj : Re: multi-threaded server, pthreads & sleep To : comp.unix.programmer,comp.programming.threads,comp.lang.c From : Pascal Bourguignon Date : Wed Mar 16 2005 02:05 pm parahat@gmail.com (Parahat Melayev) writes: > I am trying to writa a multi-client & multi-threaded TCP server. > There is a thread pool. Each thread in the pool will handle requests > of multiple clients. > > But here I have a problem. I find a solution but it is not how it must > be... i think. When threads working without sleep(1) I can't get > response from server but when I put sleep(1) in thread function as you > will see in code, everything works fine and server can make echo > nearly for 40000 clients between 1 or 2 seconds. What am I doing wrong > here? I don't know, but instead of: > for(i = 0; i < MAX_CLIENT_PER_THREAD; i++) > { > if(threads[tid].clients[i] != 0) > { > n = recv(threads[tid].clients[i], buffer, MAX_CLIENT_BUFFER, 0); I'd use select(2) or poll(2). That would probably avoid the problem you're hiding with the sleep call. -- __Pascal Bourguignon__ http://www.informatimago.com/ Cats meow out of angst "Thumbs! If only we had thumbs! We could break so much!" .