diff --git a/mainapp.cpp b/mainapp.cpp index 42ba645..68de536 100644 --- a/mainapp.cpp +++ b/mainapp.cpp @@ -538,12 +538,21 @@ void MainApp::start() uint64_t eventfd_value = 0; check(read(cur_fd, &eventfd_value, sizeof(uint64_t))); - std::lock_guard locker(eventMutex); - for(auto &f : taskQueue) + std::forward_list> tasks; + + { + std::lock_guard locker(eventMutex); + for (auto &f : taskQueue) + { + tasks.push_front(f); + } + taskQueue.clear(); + } + + for(auto &f : tasks) { f(); } - taskQueue.clear(); } } catch (std::exception &ex)