Sanitizer fixes (#2280)

This commit is contained in:
Tim Sylvester
2024-04-29 06:33:08 -07:00
committed by GitHub
parent 6ebbc3dd6a
commit cd9727b06f
14 changed files with 85 additions and 37 deletions

View File

@@ -59,23 +59,28 @@ std::thread ThreadedSchedulerBase::makeSchedulerThread(size_t index) {
lock.unlock();
if (function) {
const auto cleanup = [&] {
// destroy the function and release its captures before unblocking `waitForEmpty`
function = {};
pendingItems--;
if (queue.empty() && !pendingItems) {
cvEmpty.notify_all();
}
};
try {
function();
cleanup();
// destroy the function and release its captures before unblocking `waitForEmpty`
function = {};
if (!--pendingItems) {
std::unique_lock<std::mutex> inner_lock(mutex);
if (queue.empty()) {
cvEmpty.notify_all();
}
}
} catch (...) {
lock.lock();
std::unique_lock<std::mutex> inner_lock(mutex);
if (handler) {
handler(std::current_exception());
}
cleanup();
function = {};
if (!--pendingItems && queue.empty()) {
cvEmpty.notify_all();
}
if (handler) {
continue;
}