SingleProducerConstrained和MaxDegreeOfParallelism [英] SingleProducerConstrained and MaxDegreeOfParallelism

查看:60
本文介绍了SingleProducerConstrained和MaxDegreeOfParallelism的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#TPL数据流库中,SingleProducerConstrained是ActionBlocks的优化选项,当只有单个线程正在馈送动作块时,可以使用它:

In the C# TPL Dataflow library, SingleProducerConstrained is an optimisation option for ActionBlocks you can use when only a single thread is feeding the action block:

如果一个区块仅由单个生产者使用, 时间,也就是说一次只能使用一个线程 在块上发布,提供消息和完成,此属性可能是 设置为true以通知该块它不需要额外应用 同步.

If a block is only ever going to be used by a single producer at a time, meaning only one thread at a time will be using methods like Post, OfferMessage, and Complete on the block, this property may be set to true to inform the block that it need not apply extra synchronization.

如果使用具有MaxDegreeOfPArallelism> 1的单个TransformBlock馈送ActionBlock怎么办?会违反在ActionBlock上将SingleProcerContrained设置为true的规则吗?还是具有MaxDegreeOfPArallelism> 1的单个TransformBlock仍被视为单一生产者"?

What if an ActionBlock is fed using a single TransformBlock which have MaxDegreeOfPArallelism > 1 - would that violate the rules for setting SingleProcerContrained to true on the ActionBlock? or is a single TransformBlock with MaxDegreeOfPArallelism > 1 still counted as a "single producer"?

推荐答案

是的,我认为它被视为单个生产者.

Yes, I think it's considered a single producer.

这是因为所有内置模块都保持排序,因此可以提供项目2(使用

This is because all the built-int blocks maintain ordering, so item 2 can be offered (using the OfferMessage() method) to the target block only after item 1 has been accepted. And this constraint means that there can be only one thread offering messages to the target at a time, which follows the definition of "single producer".

这篇关于SingleProducerConstrained和MaxDegreeOfParallelism的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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