Skip to content

Commit

Permalink
More work on #894: Race condition at shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Sep 28, 2013
1 parent 0d1ca91 commit 02ca1be
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions hpx/lcos/detail/future_data.hpp
Expand Up @@ -677,13 +677,14 @@ namespace detail

if (sched_) {
sched_->add(HPX_STD_BIND(&task_base::run_impl, this_),
"task_base::apply", threads::pending, false);
"task_base::apply", threads::pending, false,
stacksize, ec);
}
else {
threads::register_thread_plain(
HPX_STD_BIND(&task_base::run_impl, this_),
"task_base::apply", threads::pending, false,
priority, std::size_t(-1), stacksize);
priority, std::size_t(-1), stacksize, ec);
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/runtime/naming/name.cpp
Expand Up @@ -7,6 +7,7 @@
#include <hpx/hpx_fwd.hpp>
#include <hpx/runtime/naming/name.hpp>
#include <hpx/exception.hpp>
#include <hpx/state.hpp>
#include <hpx/util/portable_binary_iarchive.hpp>
#include <hpx/util/portable_binary_oarchive.hpp>
#include <hpx/util/base_object.hpp>
Expand Down Expand Up @@ -84,12 +85,25 @@ namespace hpx { namespace naming
// FIXME: The address should still be in the cache, but it could
// be evicted. It would be nice to have a way to pass the address
// directly to free_component_sync.
components::stubs::runtime_support::free_component_sync(t, *p, 1);
try {
using components::stubs::runtime_support;
runtime_support::free_component_sync(t, *p, 1);
}
catch (hpx::exception const& e) {
// This request might come in too late and the thread manager
// was already stopped. We ignore the request if that's the
// case.
if (e.get_error() != invalid_status) {
throw; // rethrow if not invalid_status
}
else if (!threads::threadmanager_is(hpx::stopping)) {
throw; // rethrow if not stopping
}
}
}
delete p; // delete local gid representation in any case
}


// custom deleter for managed gid_types, will be called when the last
// copy of the corresponding naming::id_type goes out of scope
void gid_managed_deleter (id_type_impl* p)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/threads/policies/hwloc_topology.cpp
Expand Up @@ -681,10 +681,10 @@ namespace hpx { namespace threads

if (first) {
first = false;
os << std::setw(6) << num_thread << ": ";
os << std::setw(4) << num_thread << ": ";
}
else {
os << " ";
os << " ";
}

detail::print_info(os, obj);
Expand Down
24 changes: 17 additions & 7 deletions src/util/query_counters.cpp
Expand Up @@ -101,7 +101,7 @@ namespace hpx { namespace util
{
find_counters();

for (std::size_t i = 0; i < ids_.size(); ++i)
for (std::size_t i = 0; i != ids_.size(); ++i)
{
// start the performance counter
using performance_counters::stubs::performance_counter;
Expand Down Expand Up @@ -145,6 +145,7 @@ namespace hpx { namespace util

void query_counters::terminate()
{
mutex_type::scoped_lock l(mtx_);
ids_.clear(); // give up control over all performance counters
}

Expand All @@ -171,7 +172,7 @@ namespace hpx { namespace util
std::vector<future<bool> > started;

started.reserve(ids_.size());
for (std::size_t i = 0; i < ids_.size(); ++i)
for (std::size_t i = 0; i != ids_.size(); ++i)
started.push_back(performance_counter::start_async(ids_[i]));

// wait for all counters to be started
Expand Down Expand Up @@ -200,7 +201,7 @@ namespace hpx { namespace util
std::vector<future<bool> > stopped;

stopped.reserve(ids_.size());
for (std::size_t i = 0; i < ids_.size(); ++i)
for (std::size_t i = 0; i != ids_.size(); ++i)
stopped.push_back(performance_counter::stop_async(ids_[i]));

// wait for all counters to be started
Expand Down Expand Up @@ -229,7 +230,7 @@ namespace hpx { namespace util
std::vector<future<void> > reset;

reset.reserve(ids_.size());
for (std::size_t i = 0; i < ids_.size(); ++i)
for (std::size_t i = 0; i != ids_.size(); ++i)
reset.push_back(performance_counter::reset_async(ids_[i]));

// wait for all counters to be started
Expand Down Expand Up @@ -263,13 +264,22 @@ namespace hpx { namespace util
return false;
}

std::vector<id_type> ids;
{
mutex_type::scoped_lock l(mtx_);
ids = ids_;
}

if (ids.empty())
return false;

// Query the performance counters.
using performance_counters::stubs::performance_counter;
std::vector<future<performance_counters::counter_value> > values;

values.reserve(ids_.size());
for (std::size_t i = 0; i < ids_.size(); ++i)
values.push_back(performance_counter::get_value_async(ids_[i], reset));
values.reserve(ids.size());
for (std::size_t i = 0; i != ids.size(); ++i)
values.push_back(performance_counter::get_value_async(ids[i], reset));

util::osstream output;
if (description)
Expand Down

0 comments on commit 02ca1be

Please sign in to comment.