Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SingleProducerConstrained and MaxDegreeOfParallelism

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

like image 370
Stig Schmidt Nielsson Avatar asked Mar 18 '14 08:03

Stig Schmidt Nielsson


1 Answers

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

like image 182
svick Avatar answered Sep 28 '22 05:09

svick