SingleProducerConstrained and MaxDegreeOfParallelism

给你一囗甜甜゛ 提交于 2019-12-03 17:37:15

问题


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:

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.

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"?


回答1:


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

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".



来源:https://stackoverflow.com/questions/22474082/singleproducerconstrained-and-maxdegreeofparallelism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!