none
task_group use-case RRS feed

  • Question

  • I have recently begun looking into concurrency::task_group and ran into this following snippet on MSDN:

    "Use task_group when you have several independent tasks that you want to execute at the same time, but you want to **wait for the tasks to finish at a later time** "

    Does this imply that tasks initiated via task_group::run ought to be logically related to each other, so you can wait (or cancel) on them at a later date? What if I simply have to do something like this:

    for (while_we_still_have_context_data_in_a_queue) {

        Context* ctx = queue.pop_context();

        ProcessContext(ctx);

    }

    Can I possibly change that to:

    for (while_we_still_have_context_data_in_a_queue) {

        Context* ctx = queue.pop_context();

        my_task_group.run([ctx]() { ProcessContext(ctx); });

    }

    Here one iteration of ProcessContext has nothing to do with another and each such task can just complete independently.

    Would task_group be a good fit for this scenario? (I am concerned by the fact my_task_group's dtor might throw a missing_wait exception if the tasks are either not cancelled or waited upon).

    Tuesday, November 5, 2013 5:08 PM

Answers

All replies