A friend of mine is trying to fix up a custom http server in C++ written for windows to work in Linux. I tried to help him, but all I found seemed too obvious.
The app creates a thread for every time a request comes in. The thread serves the request and ends. After some number of requests (something over 300) new threads are not created anymore.
All I found is that there is a limit of threads that can be created. But it looks like finished threads are still there. Is that a problem with the code or do the thread handlers never get released?
This is a bit of code my friend extracted from the app:
pthread_t threadID;
StartingArgs *arg = new StartingArgs( &(this->cameraCounts), mapToSend,&(this->mapMutex), &(this->mutex), this->config );
if( pthread_create(&threadID, NULL, (this->startingRoutine) , (void*)arg ) != 0 )
{
ConsoleMessages::printDate();
cout<< "snapshot maker: new thread creation failed\n";
}
void *CameraCounter::startingRoutine( void *arg )
{
//stuff to do. removed for debugging
delete realArgs;
return NULL;
}