jobserver: gracefully handle thread creation failures
Due to the previous DatabaseCampaign fix, this may not be necessary anymore, but it's nevertheless a good idea to handle thread creation failures properly. Change-Id: I8317a77dd5338509727e737040944320e7755ae3
This commit is contained in:
@ -171,18 +171,30 @@ void JobServer::run()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Spawn a thread for further communication,
|
|
||||||
// and add this thread to a list threads
|
bool creation_failed = false;
|
||||||
// We can limit the generation of threads here.
|
do {
|
||||||
if (m_threadlist.size() >= m_maxThreads) {
|
// Spawn a thread for further communication,
|
||||||
// Run over list with a timed_join,
|
// and add this thread to a list threads
|
||||||
// removing finished threads.
|
// We can limit the generation of threads here.
|
||||||
do {
|
if (m_threadlist.size() >= m_maxThreads || creation_failed) {
|
||||||
m_threadlist.remove_if(timed_join_successful(m_threadtimeout));
|
// Run over list with a timed_join,
|
||||||
} while (m_threadlist.size() == m_maxThreads);
|
// removing finished threads.
|
||||||
}
|
do {
|
||||||
// Start new thread
|
m_threadlist.remove_if(timed_join_successful(m_threadtimeout));
|
||||||
th = new boost::thread(CommThread(cs, *this));
|
} while (m_threadlist.size() >= m_maxThreads);
|
||||||
|
}
|
||||||
|
// Start new thread
|
||||||
|
try {
|
||||||
|
th = new boost::thread(CommThread(cs, *this));
|
||||||
|
creation_failed = false;
|
||||||
|
} catch (boost::thread_resource_error e) {
|
||||||
|
cout << "failed to spawn thread, throttling ..." << endl;
|
||||||
|
creation_failed = true;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
} while (creation_failed);
|
||||||
|
|
||||||
m_threadlist.push_back(th);
|
m_threadlist.push_back(th);
|
||||||
}
|
}
|
||||||
close(s);
|
close(s);
|
||||||
|
|||||||
Reference in New Issue
Block a user