CScheduler::serviceQueue has the following code:
+ lock.unlock();
+ f();
+ lock.lock();
+ } catch (...) {
+ --nThreadsServicingQueue;
+ throw;
+ }
In case f throws the statement --nThreadsServicingQueue; will run while not protected by the lock. This is a race condition and UB.