我的一位朋友正在嘗試修復一個用C++編寫的自定義http服務器,用於在Linux中工作。我試圖幫助他,但我發現的一切似乎都很明顯。Linux C++線程已死,但「掛起」 - 線程限制
該應用程序爲每次請求進入時創建一個線程。該線程爲請求提供服務並結束。經過一些請求(超過300個)後,不再創建新的線程。
我發現的所有內容都是可以創建的線程的限制。但看起來完成的線程仍然存在。這是代碼的問題還是線程處理程序永遠不會被釋放?
這是一段代碼我的朋友從應用程序中提取:
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;
}
謝謝。我記得看到一個版本,有一個在pthread_join調用,它並沒有幫助的代碼,但是這看起來不錯。 – naugtur 2010-10-23 20:55:14
加入可能是有用的,但在這樣一個設置,它會導致線程串行化,這是不是你想要的。 – 2010-10-25 03:21:34