Skip to content

Commit 055b7b8

Browse files
author
Chris Sullivan
committed
Enabled stopWorkers flag to terminate threads
1 parent d8bda53 commit 055b7b8

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

include/ThreadPool.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public:
6363
m_promises[mypromise].set_value();
6464
});
6565
}
66+
WorkType work;
6667
if (m_taskQueue.try_dequeue(work)) work(); // master thread is also a worker
6768
Finish();
6869
}

src/ThreadPool.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@ ThreadPool::ThreadPool(uint32_t numthreads) : m_nthreads(numthreads), m_stopWork
77
}
88
ThreadPool::~ThreadPool() {
99
m_stopWorkers = true;
10-
m_taskQueue.join();
1110
JoinAll();
1211
}
1312

1413
void ThreadPool::Worker() {
1514
while(true) {
1615
function<void()> work;
17-
try {
18-
if (m_taskQueue.try_dequeue(work)) work();
19-
}
20-
catch (const ThreadsafeQueue<WorkType>::QueueFinished&)
21-
{
22-
return;
23-
}
16+
if (m_taskQueue.try_dequeue(work)) work();
17+
if (m_stopWorkers) return;
2418
}
2519
}
2620
void ThreadPool::JoinAll() {

0 commit comments

Comments
 (0)