Quantcast
Viewing all articles
Browse latest Browse all 4845

New Post: Unable to cancel task

Consider this snippet:
    pplx::task_completion_event<void> ev;
    pplx::cancellation_token_source cts;
    pplx::create_task([ev] 
    {
        Sleep(1000);
        pplx::interruption_point();
        //if (pplx::is_task_cancellation_requested())
        //  pplx::cancel_current_task();
        ev.set();
    }, cts.get_token());
    pplx::create_task([&cts]
    {
        Sleep(500); 
        cts.cancel();
    });
    auto t = pplx::task<void>(ev);
    try
    {
        t.wait();
        std::cout << "Hello World!\n";
    }
    catch (...)
    {
        std::cout << "Error!\n";
    }
I expect it to print "Error!" since the task is cancelled and there is an interruption point in the task that is canceled, but using the latest dev branch, this runs and prints "Hello World!" contrary to my expectations. Am I doing something wrong here? Maybe I'm not understanding how to cancel things properly.

Also, I'm not 100% sure on the semantics of task_completion_event, so this is just some test code. Nevertheless, I've verified using the debugger that evne if cts.cancel() is called before pplx::interruption_point, the function does not throw and continues as usual. Also for some strange reason, pplx::is_task_cancellation_requested can not be found in VS14.

I'm using latest dev because I'm using VS14.

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>