Problem/Bug in pplx?

Sep 24, 2015 at 9:23 AM
Hello,

I am using pplx on Windows and Linux.

To enforce explicit use of schedulers, I call set_ambient_scheduler(MyInvalidScheduler()) at the beginning of my program. This way I catch the cases where somebody did not explicitly provide a scheduler.

Now something curious can happen. First I create a task with a specific scheduler, then - before the task is actually executed - I chain a continuation to it. Next the task will execute and throw an exception. This will then go through a bunch of functions within ppl (for an exact stack trace see below - with direct links to source here on codeplex). Ultimately _RunTask will do
get_ambient_scheduler()->schedule(_Proc, _Parameter);
This strikes me as odd, as pplx is not using my provided schedulers and instead relies on the ambient scheduler for certain things. Since my ambient scheduler is invalid (see above), things break.

Since I couldn't believe pplx has to rely on the ambient scheduler, I looked at the corresponding code in the PPL. I ended up at pplconcrt.h where the line in _RunTask reads
_CurrentScheduler::_ScheduleTask(_Proc, _Parameter);
So there it explicitly uses the CurrentScheduler and not some ambient scheduler out of the blue.

So my final questions :
  1. Is the ambient scheduler just some nice default when creating tasks or is it inherently needed to make pplx work at all?
  2. Is this a "not implemented" thing in PPLX compared to PPL because there's no ConcRT in PPLX that provides _CurrentScheduler?
  3. What can I do to prevent pplx using schedulers I do not want it to use? -- I guess one way would be to have my schedulers set a thread-local "currentScheduler" variable and then in my InvalidScheduler use this one to figure out the currentScheduler and instead forward to that one?
Detailed stack trace with direct links to code in question:

_CancelAndRunContinuations
_ScheduleFuncWithAutoInline
_RunTask


Thank you very much,
-Matthias
Sep 24, 2015 at 1:04 PM
Addendum:

I've hacked pplx so that _ScheduleFuncWithAutoInline and _RunTask take a scheduler_ptr now. In the two places that call _ScheduleFuncWithAutoInline I pass _M_TaskCollection._GetScheduler(). This way I don't need no ambient scheduler anymore.

Does this sound OK or is there some problem I didn't see?

If I create a pull request for a change like this, do I have any chances of getting it accepted?
Sep 24, 2015 at 8:38 PM
Edited Sep 24, 2015 at 8:39 PM
This does sound like a bug; the ambient scheduler should not be required.

Great work tracking this down. I think your fix sounds reasonable, so please do submit a pull request.

Note: you'll also need to sign our contributor agreement. Take a look at https://casablanca.codeplex.com/wikipage?title=Make%20a%20contribution&referringTitle=Documentation for more.