diff --git a/cond_variable_instead_sleep_for.patch b/cond_variable_instead_sleep_for.patch new file mode 100644 index 00000000..872366e0 --- /dev/null +++ b/cond_variable_instead_sleep_for.patch @@ -0,0 +1,46 @@ +--- worker.hpp Thu Mar 22 23:20:12 2018 ++++ worker.hpp Sat Mar 24 22:28:13 2018 +@@ -2,6 +2,8 @@ + + #include + #include ++#include ++#include + + namespace tp + { +@@ -78,6 +80,8 @@ + Queue m_queue; + std::atomic m_running_flag; + std::thread m_thread; ++ std::mutex m_conditional_mutex; ++ std::condition_variable m_conditional_lock; + }; + + +@@ -121,6 +125,7 @@ + inline void Worker::stop() + { + m_running_flag.store(false, std::memory_order_relaxed); ++ m_conditional_lock.notify_all(); + m_thread.join(); + } + +@@ -140,6 +145,7 @@ + template + inline bool Worker::post(Handler&& handler) + { ++ m_conditional_lock.notify_one(); + return m_queue.push(std::forward(handler)); + } + +@@ -171,7 +177,8 @@ + } + else + { +- std::this_thread::sleep_for(std::chrono::milliseconds(1)); ++ std::unique_lock lock(m_conditional_mutex); ++ m_conditional_lock.wait(lock); + } + } + }