净TPL:有限并行级别任务调度程序任务的优先级? [英] .Net TPL: Limited Concurrency Level Task scheduler with task priority?

查看:161
本文介绍了净TPL:有限并行级别任务调度程序任务的优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用这里的http://msdn.microsoft.com/en-us/library/ee789351.aspx

我想加强这使个人任务可以被分配优先级。这些优先事项不一定映射到线程的优先级。它应该只影响在任务启动的顺序。

I want to enhance this so that individuals tasks can be assigned priority. These priorities need not map to thread priority. It should only influence the order in which tasks are started.

有谁知道这样一个任务调度程序的例子吗? (很多调度的东西是在我的头上,所以如果有一个现有的解决方案将是巨大的)

Does anyone know of an example of such a task scheduler? (a lot of the scheduling stuff is over my head so it would be great if there was an existing solution)

推荐答案

并行扩展额外的样品。已经提供了这样的调度,所述QueuedTaskScheduler。该调度程序提供的优先级,并发限制,公平性和细粒度控制的类型和所使用的线程的优先级。当然,你不必使用或配置您不需要的功能。

The Parallel Extensions Extras Samples. already provide such a scheduler, the QueuedTaskScheduler. This scheduler provides priorities, concurrency limits, fairness and fine-grained control over the type and priorities of the threads used. Of course, you don't have to use or configure the features you don't need.

斯蒂芬Toub提供的各种调度的简要说明,在并行扩展附加这里

Stephen Toub provides a brief description of the various schedulers in the Parallel Extensions Extras here

要使用QueuedTaskScheduler,你调用它的ActivateNewQueue方法,你需要的优先级。此方法返回父的TaskScheduler管理的新的TaskScheduler派生的Queue对象。使用一个特定的队列中的所有任务都是由父母定的TaskScheduler根据其优先级。

To use the QueuedTaskScheduler, you call its ActivateNewQueue method with the priority you need. This method returns a new TaskScheduler-derived Queue object managed by the parent TaskScheduler. All tasks that use a specific queue are scheduled by the parent TaskScheduler according to their priorities.

下面code创建一个用4,2个优先级队列和调度上的第一队列的任务​​的最大并发级别的调度:

The following code creates a scheduler with a maximum concurrency level of 4, two priority queues and schedules a task on the first queue:

QueuedTaskScheduler qts = new QueuedTaskScheduler(TaskScheduler.Default,4);
TaskScheduler pri0 = qts.ActivateNewQueue(priority: 0);
TaskScheduler pri1 = qts.ActivateNewQueue(priority: 1);

Task.Factory.StartNew(()=>{ }, 
                      CancellationToken.None, 
                      TaskCreationOptions.None, 
                      pri0);

这篇关于净TPL:有限并行级别任务调度程序任务的优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆