locked
[UWP][C++]tasks queue

    Question

  • Hello

    I need to set some tasks in queue, but dont know how

    Model is:

    I have some task task1 = [](){} (generated by lambda for example). This task is only generated and not start executing.

    Tasks generated in separate threads.

    After generating i push this task in some queue.

    Queue executing task only after previous task.

    How better implement it?

    If WRL is the only way i need some explanation of how build system i describe


    Monday, April 27, 2015 3:05 PM

All replies

  • Due to task_group it thread-safe. But this code fails:

    concurrency::task_group tg;
    
    create_async([this, &tg]()
    {			
    	tg.run_and_wait([this]()
    	{		
    		for (auto i = 1; i < 1000; i++)
    		{
    			auto a = 1000000000 / i;
    		}
    					
    	});
    			
    });

    How can i make safe access to task_group object?


    Monday, April 27, 2015 4:45 PM
  • Hi Romka2411,

    How about ContinueWith(TResult) Method (Func(Task, TResult))?

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 28, 2015 3:30 AM
    Moderator
  • You need to synchronize access to a variable, e.g. using a mutex

    task_group is thread-safe means that you can add tasks to a task_group object from multiple threads and wait on or cancel a task_group object from multiple threads: https://msdn.microsoft.com/en-us/library/dd492427.aspx


    Best Regards,
    Please remember to mark the replies as answers if they help

    Tuesday, April 28, 2015 7:44 AM
  • Am i need to call mutex in thread which task_group exist? Because now im trying use mutex in thread which adding tasks to task_group.

    Also, even if there no other access (like in example i wrote) this code fails when i try work with task_group - even .wait() method fail whole program

    Tuesday, April 28, 2015 11:56 AM
  • Seems like using concurrency::task_group is solve my problem (Find it just last night). There is just one problem yet - how to access to this task_group from other thread - and i will be totally happy

    Tuesday, April 28, 2015 3:20 PM
  • Nice to know you have the C++ solution.

    But I have a question regarding your second question, what do you want to get after access the task_group, as I know task_group is a class, we can initialize it and it as public, after that we should be able to access the task_group instance from everywhere.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 01, 2015 8:00 AM
    Moderator
  • im discovered that this code fails

    concurrency::task_group tg;
    
    create_task([this, &tg]()
    {
    	tg.run_and_wait([](){});
    		
    });


    • Edited by Romka2411 Wednesday, May 06, 2015 8:38 AM
    Wednesday, May 06, 2015 8:36 AM