Influencing the Task Scheduler from within a component RRS feed

  • Question

  • Hi all,

    in our C++ component we want to make sure that all tasks that are created there will be run sequentially. E.g. if the Javascript app issues two SQL statements to be run, the task for the second one shouldn't be performed until the first one has completed.

    Since it isn't really a continuation, we cannot chain these tasks using 'then' but also the whole Concurrency::Scheduler API isn't available in the component.

    Any tips how to achieve this behaviour? Essential we would need some kind of task queue. My next approach would be to try and create some Concurrency::task_handle, put them into a queue and process them one by one. But I don't know if or how I can convert task_handle into IAsyncAction to return it back to the main app.

    All the best


    Friday, July 20, 2012 4:06 PM

All replies

  • To clarify the scenario in question, you are wanting your C++ component to have the ability to receive concurrent requests, however only execute one at a time in a successive FIFO manner?

    There isn't a WinRT API for a private queue of work items. If this is the only point you can avoid the problem exposed by executing simultaneous work items, you would need to roll your own queue. I'm not sure a task would be an appropriate item to store in a queue. I'll see if I can get someone from the PPL team to chime in with their thoughts.

    David Lamb

    Monday, July 23, 2012 9:43 PM
  • Hi David,

    yes that's exactly the scenario. I thought about implementing my own queue but of course I still would want to return some IAsyncAction and IAsyncOperation back to the JavaScript so that the main thread can continue working while it has to wait for the database to process the request.

    An idea I had this morning was to keep a reference to the current/antecedent task on the database class and then wait() for it. But aside from the fact that this could wreak havoc with thread scheduling (as I understand the PPL could possibly open a lot of threads which all wait for one of the others, completely choking the thread pool), I found this quite cumbersome to do because the different methods return different types and IAsyncAction and IAsyncOperation don't have a common interface from which I could create a Concurrency:task to wait() on...

    So if someone from the PPL team could give their opinion on that matter, it would be greatly appreciated. In case you're interested, the code I'm talking about is open-sourced at https://github.com/doo/SQLite3-WinRT

    Best regards

    Edit: I tried keeping both IAsyncAction and IAsyncOperation in a struct and then waiting for the one which was set but ran into a COMException 0x80000018 : A delegate was assigned when not allowed. I'm not sure I fully understand why that happens but it looks like this approach isn't feasible after all.
    Tuesday, July 24, 2012 7:40 AM