I'm developing an application which handles client connections. I'm spawning a thread for each request, since there will be short tasks. However, I keep having a problem after handling a certain amount of connections. Specifically, after 381 connections, pthread_create fails to create a new thread. I know this can fail if the application runs out of resources, or more than PTHREAD_THREADS_MAX threads have been already created.
The strange thing is the first 381 threads have already stopped when this error occurs. I'm not using pthread_join to wait for these threads to stop, I believe pthreads don't require me to somehow "stop" the thread, correct me if i'm wrong(at least the manpage does not mention this). I thought maybe this could be produced when several threads were spawn at the same time, however, I've tested it several times and every time the 382th thread creation fails.
Does anyone know what could be happening? Any help will be appreciated.
Thanks in advance.