Skip to content

Commit

Permalink
Fixing thread scheduling when yielding a thread id.
Browse files Browse the repository at this point in the history
It might happen that the id that is being yielded to the scheduling loop
should be run on a different scheduler. This patch fixes that.
  • Loading branch information
Thomas Heller authored and sithhell committed Jan 18, 2018
1 parent e1e41ca commit 5a0d3f8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/runtime/threads/thread_helpers.cpp
Expand Up @@ -493,9 +493,17 @@ namespace hpx { namespace this_thread
#ifdef HPX_HAVE_THREAD_BACKTRACE_ON_SUSPENSION
detail::reset_backtrace bt(id, ec);
#endif

// suspend the HPX-thread
statex = self.yield(threads::thread_result_type(state, nextid));
// We might need to dispatch 'nextid' to it's correct scheduler
// only if our current scheduler is the same, we should yield the id
if (nextid && nextid->get_scheduler_base() != id->get_scheduler_base())
{
nextid->get_scheduler_base()->schedule_thread(nextid, std::size_t(-1));
statex = self.yield(threads::thread_result_type(state, nullptr));
}
else
{
statex = self.yield(threads::thread_result_type(state, nextid));
}
}

// handle interruption, if needed
Expand Down Expand Up @@ -551,9 +559,17 @@ namespace hpx { namespace this_thread
threads::thread_priority_boost, ec);
if (ec) return threads::wait_unknown;

// suspend the HPX-thread
statex = self.yield(
threads::thread_result_type(threads::suspended, nextid));
// We might need to dispatch 'nextid' to it's correct scheduler
// only if our current scheduler is the same, we should yield the id
if (nextid && nextid->get_scheduler_base() != id->get_scheduler_base())
{
nextid->get_scheduler_base()->schedule_thread(nextid, std::size_t(-1));
statex = self.yield(threads::thread_result_type(state, nullptr));
}
else
{
statex = self.yield(threads::thread_result_type(state, nextid));
}

if (statex != threads::wait_timeout)
{
Expand Down

0 comments on commit 5a0d3f8

Please sign in to comment.