From 786a1cf5ab76f94a1adece48c1de53fb32e4551e Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Tue, 31 Oct 2023 11:54:09 -0400 Subject: FIFOScheduler: fixed a few synchronization issues --- include/framework/scheduling/FIFOScheduler.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/framework/scheduling/FIFOScheduler.h b/include/framework/scheduling/FIFOScheduler.h index 5425c4f..91a72b3 100644 --- a/include/framework/scheduling/FIFOScheduler.h +++ b/include/framework/scheduling/FIFOScheduler.h @@ -43,23 +43,20 @@ public: ~FIFOScheduler() { shutdown(); - std::unique_lock lk(m_cv_lock); m_cv.notify_all(); - lk.release(); - m_sched_thrd.join(); } void schedule_job(std::function job, size_t size, void *args) { + std::unique_lock lk(m_cv_lock); size_t ts = m_counter.fetch_add(1); m_task_queue.push(Task(size, ts, job, args)); - std::unique_lock lk(m_cv_lock); m_cv.notify_all(); } void shutdown() { - m_shutdown = true; + m_shutdown.store(true); } private: @@ -68,7 +65,7 @@ private: size_t m_memory_budget; size_t m_thrd_cnt; - bool m_shutdown; + std::atomic m_shutdown; std::atomic m_counter; std::mutex m_cv_lock; @@ -80,6 +77,7 @@ private: std::atomic m_used_memory; void schedule_next() { + assert(m_task_queue.size() > 0); auto t = m_task_queue.pop(); t(); } @@ -92,8 +90,7 @@ private: while (m_task_queue.size() > 0 && m_used_thrds.load() < m_thrd_cnt) { schedule_next(); } - cv_lock.unlock(); - } while(!m_shutdown); + } while(!m_shutdown.load()); } }; -- cgit v1.2.3