Skip to content

Commit e89f5a0

Browse files
committed
drop
1 parent adb8911 commit e89f5a0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/test/threadpool_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ BOOST_AUTO_TEST_CASE(task_submitted_while_busy_completes)
245245

246246
// Wait a short moment before unblocking the threads to mimic a concurrent shutdown
247247
std::thread thread_unblocker([&blocker]() {
248-
UninterruptibleSleep(std::chrono::milliseconds{300});
248+
UninterruptibleSleep(std::chrono::seconds{5});
249+
std::cout << "unlocking threads" << std::endl;
249250
blocker.set_value();
250251
});
251252

src/util/threadpool.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ class ThreadPool
6464
std::packaged_task<void()> task;
6565
{
6666
// Wait only if needed; avoid sleeping when a new task was submitted while we were processing another one.
67-
if (!m_interrupt && m_work_queue.empty()) {
67+
//if (!m_interrupt && m_work_queue.empty()) {
6868
// Block until the pool is interrupted or a task is available.
69-
m_cv.wait(wait_lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(m_mutex) { return m_interrupt || !m_work_queue.empty(); });
70-
}
69+
std::cout << "locking thread: " << std::this_thread::get_id() << std::endl;
70+
m_cv.wait(wait_lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(m_mutex) {
71+
std::cout << "check executed, thread: " << std::this_thread::get_id() << std::endl;
72+
return m_interrupt || !m_work_queue.empty(); });
73+
std::cout << "unlocked thread: " << std::this_thread::get_id() << std::endl;
74+
//}
7175

7276
// If stopped and no work left, exit worker
7377
if (m_interrupt && m_work_queue.empty()) {
@@ -130,6 +134,7 @@ class ThreadPool
130134
std::vector<std::thread> threads_to_join;
131135
{
132136
LOCK(m_mutex);
137+
if (m_workers.empty()) return; // nothing to do
133138
// Ensure 'Stop()' isn't called from any worker thread to avoid deadlocks
134139
auto id = std::this_thread::get_id();
135140
for (const auto& worker : m_workers) assert(worker.get_id() != id);
@@ -138,6 +143,7 @@ class ThreadPool
138143
threads_to_join.swap(m_workers);
139144
}
140145
m_cv.notify_all();
146+
std::cout << "post notify" << std::endl;
141147
for (auto& worker : threads_to_join) worker.join();
142148
// Since we currently wait for tasks completion, sanity-check empty queue
143149
WITH_LOCK(m_mutex, Assume(m_work_queue.empty()));

0 commit comments

Comments
 (0)