mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-23 13:05:11 +00:00
workPool: handle thread init failures
This commit is contained in:
parent
1a520dbf3e
commit
157f3be253
2 changed files with 20 additions and 4 deletions
|
@ -100,9 +100,16 @@ void DivWorkThread::finish() {
|
|||
thread->join();
|
||||
}
|
||||
|
||||
void DivWorkThread::init(DivWorkPool* p) {
|
||||
bool DivWorkThread::init(DivWorkPool* p) {
|
||||
parent=p;
|
||||
thread=new std::thread(_workThread,this);
|
||||
try {
|
||||
thread=new std::thread(_workThread,this);
|
||||
} catch (std::system_error& e) {
|
||||
logE("could not start thread! %s",e.what());
|
||||
thread=NULL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DivWorkPool::push(void (*what)(void*), void* arg) {
|
||||
|
@ -171,7 +178,16 @@ DivWorkPool::DivWorkPool(unsigned int threads):
|
|||
if (threaded) {
|
||||
workThreads=new DivWorkThread[threads];
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
workThreads[i].init(this);
|
||||
if (!workThreads[i].init(this)) {
|
||||
count=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count<=0) {
|
||||
logE("DivWorkPool: couldn't start any threads! falling back to non-threaded mode.");
|
||||
delete[] workThreads;
|
||||
threaded=false;
|
||||
workThreads=NULL;
|
||||
}
|
||||
} else {
|
||||
workThreads=NULL;
|
||||
|
|
|
@ -57,7 +57,7 @@ struct DivWorkThread {
|
|||
bool busy();
|
||||
void finish();
|
||||
|
||||
void init(DivWorkPool* p);
|
||||
bool init(DivWorkPool* p);
|
||||
DivWorkThread():
|
||||
parent(NULL),
|
||||
isBusy(false),
|
||||
|
|
Loading…
Reference in a new issue