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 b709d11
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/runtime/threads/thread_helpers.cpp
Expand Up @@ -493,9 +493,18 @@ 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.get(), 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 +560,20 @@ 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.get(), std::size_t(-1));
statex = self.yield(
threads::thread_result_type(threads::suspended, nullptr));
}
else
{
statex = self.yield(
threads::thread_result_type(threads::suspended, nextid));
}

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

0 comments on commit b709d11

Please sign in to comment.