Skip to content

Commit

Permalink
Move destructor into a new cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Jul 30, 2018
1 parent 3f6f6f4 commit 467d2f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
13 changes: 13 additions & 0 deletions ThreadPool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "ThreadPool.hpp"

// the destructor joins all threads
ThreadPool::~ThreadPool() {
{
std::unique_lock<std::mutex> lock(queue_mutex);
stop = true;
}
condition.notify_all();
for (std::thread& worker : workers) {
worker.join();
}
}
12 changes: 0 additions & 12 deletions ThreadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,4 @@ auto ThreadPool::enqueue(F&& f, Args&&... args)
return res;
}

// the destructor joins all threads
ThreadPool::~ThreadPool()
{
{
std::unique_lock<std::mutex> lock(queue_mutex);
stop = true;
}
condition.notify_all();
for(std::thread &worker: workers)
worker.join();
}

#endif
7 changes: 5 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ project('ThreadPool', ['cpp'], default_options : ['cpp_std=c++17'])

threads_dep = dependency('threads')

test('Example', executable('example', sources : ['example.cpp'], dependencies : [threads_dep]))
lib = static_library('ThreadPool', 'ThreadPool.cpp')

test('Example', executable('example', sources : ['example.cpp'], dependencies : [threads_dep],
link_with : lib))

install_headers('ThreadPool.hpp')

inc = include_directories('.')
threadpool_dep = declare_dependency(include_directories : inc)
threadpool_dep = declare_dependency(include_directories : inc, link_with : lib)

0 comments on commit 467d2f4

Please sign in to comment.