Skip to content

Commit

Permalink
One more attempt to fix the service_executor
Browse files Browse the repository at this point in the history
Instead of an hpx condition variable, we need the one from std:: to avoid getting
failures due to tasks being run on non-HPX worker threads.
  • Loading branch information
Thomas Heller committed Sep 15, 2017
1 parent 4cb2256 commit c50c064
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions hpx/runtime/threads/executors/service_executors.hpp
Expand Up @@ -8,18 +8,20 @@

#include <hpx/config.hpp>
#include <hpx/exception_fwd.hpp>
#include <hpx/lcos/local/condition_variable.hpp>
#include <hpx/runtime/threads/thread_enums.hpp>
#include <hpx/runtime/threads/thread_executor.hpp>
#include <hpx/throw_exception.hpp>
#include <hpx/util/atomic_count.hpp>
#include <hpx/util/steady_clock.hpp>
#include <hpx/util/thread_description.hpp>
#include <hpx/util/unique_function.hpp>

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <cstdint>
#include <mutex>

#include <hpx/config/warnings_prefix.hpp>

Expand Down Expand Up @@ -73,10 +75,10 @@ namespace hpx { namespace threads { namespace executors

private:
util::io_service_pool* pool_;
typedef hpx::lcos::local::spinlock mutex_type;
typedef std::mutex mutex_type;
mutex_type mtx_;
std::atomic<std::uint64_t> task_count_;
lcos::local::condition_variable_any shutdown_cv_;
hpx::util::atomic_count task_count_;
std::condition_variable_any shutdown_cv_;
};
}

Expand Down
8 changes: 6 additions & 2 deletions src/runtime/threads/executors/service_executor.cpp
Expand Up @@ -26,6 +26,8 @@
#include <string>
#include <utility>

#include <iostream>

namespace hpx { namespace threads { namespace executors { namespace detail
{
///////////////////////////////////////////////////////////////////////////
Expand All @@ -44,7 +46,7 @@ namespace hpx { namespace threads { namespace executors { namespace detail
service_executor::~service_executor()
{
std::unique_lock<mutex_type> l(mtx_);
while (task_count_ != 0)
while (task_count_ > 0)
{
shutdown_cv_.wait(l);
}
Expand All @@ -56,11 +58,13 @@ namespace hpx { namespace threads { namespace executors { namespace detail

// By hanging on to the lock during notify_all, we ensure that the
// destructor is only completed after this function returned
std::unique_lock<mutex_type> l(mtx_);
{
std::unique_lock<mutex_type> l(mtx_);
HPX_ASSERT(task_count_ > 0);
if (--task_count_ == 0)
{
shutdown_cv_.notify_all();
}
}
}

Expand Down

0 comments on commit c50c064

Please sign in to comment.