Skip to content

Commit 467d2f4

Browse files
committed
Move destructor into a new cpp file
1 parent 3f6f6f4 commit 467d2f4

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

ThreadPool.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "ThreadPool.hpp"
2+
3+
// the destructor joins all threads
4+
ThreadPool::~ThreadPool() {
5+
{
6+
std::unique_lock<std::mutex> lock(queue_mutex);
7+
stop = true;
8+
}
9+
condition.notify_all();
10+
for (std::thread& worker : workers) {
11+
worker.join();
12+
}
13+
}

ThreadPool.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,4 @@ auto ThreadPool::enqueue(F&& f, Args&&... args)
7777
return res;
7878
}
7979

80-
// the destructor joins all threads
81-
ThreadPool::~ThreadPool()
82-
{
83-
{
84-
std::unique_lock<std::mutex> lock(queue_mutex);
85-
stop = true;
86-
}
87-
condition.notify_all();
88-
for(std::thread &worker: workers)
89-
worker.join();
90-
}
91-
9280
#endif

meson.build

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ project('ThreadPool', ['cpp'], default_options : ['cpp_std=c++17'])
22

33
threads_dep = dependency('threads')
44

5-
test('Example', executable('example', sources : ['example.cpp'], dependencies : [threads_dep]))
5+
lib = static_library('ThreadPool', 'ThreadPool.cpp')
6+
7+
test('Example', executable('example', sources : ['example.cpp'], dependencies : [threads_dep],
8+
link_with : lib))
69

710
install_headers('ThreadPool.hpp')
811

912
inc = include_directories('.')
10-
threadpool_dep = declare_dependency(include_directories : inc)
13+
threadpool_dep = declare_dependency(include_directories : inc, link_with : lib)

0 commit comments

Comments
 (0)