From 157f3be2539062d338302e5f62f60fa821e968d5 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 7 Sep 2023 01:16:12 -0500 Subject: [PATCH] workPool: handle thread init failures --- src/engine/workPool.cpp | 22 +++++++++++++++++++--- src/engine/workPool.h | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/engine/workPool.cpp b/src/engine/workPool.cpp index f871eab82..60d580acf 100644 --- a/src/engine/workPool.cpp +++ b/src/engine/workPool.cpp @@ -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