Skip to content

Commit

Permalink
Merge pull request #3109 from STEllAR-GROUP/fix_scheduling
Browse files Browse the repository at this point in the history
Fixing thread scheduling when yielding a thread id.
  • Loading branch information
msimberg authored Jan 19, 2018
2 parents 8bdfa43 + b709d11 commit 57730a9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/runtime/threads/thread_helpers.cpp
Original file line number Diff line number Diff line change
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 57730a9

Please sign in to comment.