task - VC++ PPL,将调度程序分配给task_group

标签 task scheduler ppl

假设我们有一个类:

class Foo
{
private:
 Concurrency::task_group _tasks;  
};

如何为该任务组分配调度程序?我不想使用默认调度程序,因为我还在代码中的其他地方使用parallel_for。

task_group 将通过调度程序设置其最大并发级别,以根据时间使用所有核心或其中的子集。该应用程序可能会运行几个小时,因此需要更改最大并发数。

我在 PPL 中找不到执行此操作的好方法。在 .NET 中,这非常简单 - 您所要做的就是设置 MaxDegreeOfParallelism。

有什么想法吗?

最佳答案

有几种解决方案:

  1. 如果您使用 MSVS C++ 2012,则:

    _tasks.run([]()
    {
        Context::Oversubscribe(true);
        //
        // long time running task
        //
       Context::Oversubscribe(false);
    });
    
  2. 如果您的应用程序在 Win7x64 或 Windows Server 2008 R2 上运行,请尝试 UMS :

    Scheduler::SetDefaultSchedulerPolicy( SchedulerPolicy(1, SchedulerKind, UmsThreadDefault) );
    
  3. 最后。在创建新的繁重任务之前,使用新的超额订阅策略(放大 MaxConcurrency)创建新的当前调度程序。

    CurrentScheduler::Create( SchedulerPolicy(1, MaxConcurrency, 8) );
    _tasks.run([](){
        //
        // long time running task
        //
     });
    CurrentScheduler::Detach();
    

关于task - VC++ PPL,将调度程序分配给task_group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115440/

相关文章:

mysql - 如何在mysql workbench中安排工作

c - 如何编写 I/O 绑定(bind) C 程序?

c++ - Rxcpp 中的调度器

c++ - ppl,如何正确使用它?

c# - 为什么不等待我传递给 Task.Run() 的异步操作?

linux - 在交换器中执行时,Linux 内核模块中的任务所有者 pid

c# - 等待 IO 的线程会阻塞 CPU 吗?

parsing - 左递归和右递归是否产生相同的解析树?

c# - 任务.WaitSubset/任务.WaitN?

c# - Task.ContinueWith(..., TaskScheduler.FromCurrentSynchronizationContext()) *不* 在 UI 线程上运行的任何场景?