Potential deadlock when threw exception

May 7, 2015 at 4:54 PM
Edited May 7, 2015 at 9:15 PM
I discovered potential deadlock when threw exception from function "schedule". Code below:
Release\src\pplx\pplxwin.cpp:

 if (!work)
        {
            delete schedulerParam;
            throw utility::details::create_system_error(GetLastError());
        }
I locally fix this problem. Path below:
Index: pplxtasks.h
===================================================================
--- pplxtasks.h (revision 298)
+++ pplxtasks.h (working copy)
@@ -2000,6 +2000,7 @@
                 // This exception could only have come from within the chore body. It should've been caught
                 // and the task should be canceled with exception. Swallow the exception here.
                 _ASSERTE(_HasUserException());
+               _CancelWithException(std::current_exception());
             }
         }
 
User code for deadlock happend (need throw exception from function schedule for second task):
#include "stdafx.h"
#include <cpprest/http_client.h>
#include <thread>

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << std::this_thread::get_id() << std::endl;
    pplx::create_task([](){
        std::cout << std::this_thread::get_id() << std::endl;
        pplx::create_task([](){
            std::cout << std::this_thread::get_id() << std::endl;
        }).get();
    }).get();
    return 0;
}
Can I get problem using this the fix? May be Could you advice me another fix?
I made some tests and all of them was passed.

This only affects when using CPPREST_FORCE_PPLX.

I think this problem will more actual when some users (like me) want to use custom Scheduler for tasks :).

p.s.
I am going to create the thread in future where I'll post my custom scheduler for discussing. I hope someone will be reviewed the code of my Scheduler and may be it will be helpful for our community :) It will be limited thread scheduler with limited subtask rank.
Coordinator
May 7, 2015 at 10:41 PM
Hi LeonidCSIT,

I agree this is a bug, continuing the discussion on the issue you opened for this as well.

Steve