Skip to content

Commit

Permalink
RTC - Fix race condition and crash
Browse files Browse the repository at this point in the history
  • Loading branch information
garythomson authored Feb 20, 2020
2 parents cee655b + 2e1892b commit a1385a4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Release/include/pplx/pplx.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _TaskCollectionImpl
else
{
_M_pScheduler->schedule(_TaskProcHandle_t::_RunChoreBridge, _PTaskHandle);
_M_scheduled_task = _PTaskHandle;
_M_scheduled_task.store(_PTaskHandle);
}
}

Expand All @@ -156,11 +156,11 @@ class _TaskCollectionImpl
void _RunAndWait()
{
// Limited inlining support for stand-alone tasks
if (_M_scheduled_task && _M_pScheduler && _M_pScheduler->unschedule(_M_scheduled_task))
auto scheduled_task = _M_scheduled_task.exchange(nullptr);
if (scheduled_task && _M_pScheduler && _M_pScheduler->unschedule(scheduled_task))
{
// Run inline
_TaskProcHandle_t::_RunChoreBridge(_M_scheduled_task);
_M_scheduled_task = nullptr;
_TaskProcHandle_t::_RunChoreBridge(scheduled_task);
}
_Wait();
}
Expand All @@ -169,8 +169,8 @@ class _TaskCollectionImpl

void _Complete()
{
_M_scheduled_task.store(nullptr);
_M_Completed.set();
_M_scheduled_task = nullptr;
}

scheduler_ptr _GetScheduler() const { return _M_pScheduler; }
Expand Down Expand Up @@ -198,7 +198,7 @@ class _TaskCollectionImpl
private:
extensibility::event_t _M_Completed;
scheduler_ptr _M_pScheduler;
_TaskProcHandle_t* _M_scheduled_task{ nullptr };
std::atomic<_TaskProcHandle_t*> _M_scheduled_task{ nullptr };
};

// For create_async lambdas that return a (non-task) result, we oversubscriber the current task for the duration of the
Expand Down

0 comments on commit a1385a4

Please sign in to comment.