What I want basically to acomplish is to schedule on a task_group new work items as work becomes available. On the task_group the run() method is called in a producer consummer scenario - such that at any given moment as work is necessary it is scheduled to be run on the task_group

Concurrency::task_group taskGroup;

tempalte <typename Functor>
void queue_work(Functor& fn)
{
    taskGroup.run([&fn](){
        fn();
    });
}

task_group requires (before exiting the app) that one calls to wait() method to free resources. I use task_group because I also need cancellation support but the need to call wait() complicates the design. Practically it seems that I would need to use an additional thread from which to call wait() on the task group from time to time (don't know if it's even legal to schedule new work on the task_group after calling wait() once or do wait() repeatedly).

How would you do it using ppl from microsoft ?

EDIT MSDN documentation states that is legal to call wait() multiple times: http://msdn.microsoft.com/en-us/library/dd470481.aspx "Calling wait on a task_group object resets it to a clean state where it can be reused. This includes the case where the task_group object was canceled."

Only thing remaining would be if one could take another approach

有帮助吗?

解决方案

My solution to this was after all to use a dedicated task created by CurrentScheduler::ScheduleTask() from where I call task_group.wait() from time to time in order to clean up accumulated Concurrency scheduler resources.

When the application wants to exit I must signal though to this task that it must end up itself (in order to clean up nicely)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top