简体   繁体   English

混合并发:: parallel_for和异步任务

[英]Mixing concurrency::parallel_for and async task

Is it "ok" to create tasks with parallel_for ? 使用parallel_for创建任务可以吗?

concurrency::concurrent_vector<concurrency::task<void>> tasks;
concurrency::parallel_for(0, length, [tasks](int i) {
    tasks.push_back(Upload_Async(i));
});
concurrency::when_all(tasks.begin(), tasks.end()).wait();

If Upload_Async is truly asynchronous, then it just starts the task and returns it, it doesn't do any of the work itself. 如果Upload_Async确实是异步的,则它只是启动任务并返回它,它本身不会做任何工作。 That means that using parallel_for here does not make any sense, it won't speed up your code, it only adds overhead. 这意味着在此处使用parallel_for没有任何意义,不会加速您的代码,只会增加开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM