summaryrefslogtreecommitdiffstats
path: root/include/framework
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2024-01-22 10:42:58 -0500
committerDouglas Rumbaugh <dbr4@psu.edu>2024-01-22 10:42:58 -0500
commit4d0d26bfef684566a371ca7c87ba84df52f25ccc (patch)
treef69984d6bfa0b79f29e00716219b34025350d41d /include/framework
parent97ddc19c2f57d54df2fe791ddedcbaf62fd1922e (diff)
downloaddynamic-extension-4d0d26bfef684566a371ca7c87ba84df52f25ccc.tar.gz
FIFOScheduler: added automake wakeup
Sometimes, when the max thread count is exceeded, it is possible for the scheduler to lock up. This is because the scheduler is only run when a new job is put into the queue, and so it is possible for a job to be blocked by thread limitations and be left sitting in the queue. If the main program is waiting on this job to finish before scheduling a new one, then the system deadlocks. I added a second background thread to the scheduler that wakes the scheduler up every 20us to resolve this and prevent these deadlocks.
Diffstat (limited to 'include/framework')
-rw-r--r--include/framework/scheduling/FIFOScheduler.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/framework/scheduling/FIFOScheduler.h b/include/framework/scheduling/FIFOScheduler.h
index 513a3a2..b77a8a1 100644
--- a/include/framework/scheduling/FIFOScheduler.h
+++ b/include/framework/scheduling/FIFOScheduler.h
@@ -10,7 +10,7 @@
#include <thread>
#include <condition_variable>
-
+#include <chrono>
#include "framework/scheduling/Task.h"
#include "framework/scheduling/statistics.h"
@@ -19,6 +19,8 @@
namespace de {
+using namespace std::literals::chrono_literals;
+
class FIFOScheduler {
private:
@@ -33,6 +35,7 @@ public:
, m_shutdown(false)
{
m_sched_thrd = std::thread(&FIFOScheduler::run, this);
+ m_sched_wakeup_thrd = std::thread(&FIFOScheduler::periodic_wakeup, this);
m_thrd_pool.resize(m_thrd_cnt);
}
@@ -77,6 +80,7 @@ private:
std::condition_variable m_cv;
std::thread m_sched_thrd;
+ std::thread m_sched_wakeup_thrd;
ctpl::thread_pool m_thrd_pool;
std::atomic<size_t> m_used_thrds;
@@ -84,6 +88,13 @@ private:
SchedulerStatistics m_stats;
+ void periodic_wakeup() {
+ do {
+ std::this_thread::sleep_for(10us);
+ m_cv.notify_all();
+ } while (!m_shutdown.load());
+ }
+
void schedule_next() {
assert(m_task_queue.size() > 0);
auto t = m_task_queue.pop();