For a threaded network application I'm developping, I have to watch the number of concurrent connections. I currently use this code:
if (curconns < maxconns) { curconns++; } else { pthread_cond_wait(&conns_is_at_max, &useless_mutex); continue; } curconns is decremented by other threads each time a connection is finished and is only incremented in the main thread. I use a condition variable to know when it is decremented so that I can restart the loop and accept the connection. I don't need a mutex but it seem the pthread code requires one. The manpages on pthreads are very scarce. Is there a better/simpler way to do this? Help is apreciated (pointers to documentation, plain answers, or just anything useful) -- "They allowed us to set up a separate division almost, that is physically, geographically, psychologically and spiritually different from what Bill himself calls the Borg" - Peter Moore, V.P. in charge of Xbox 360 marketing at Microsoft.