gpt4 book ai didi

c# - 贪心 JoinBlock 解释

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:49 25 4
gpt4 key购买 nike

In the default greedy mode, all data offered to targets are accepted, even if the other target doesn’t have the necessary data with which to form a tuple

据此,我的理解是我可以使用下一个片段接收。

var block = new JoinBlock<int,int>(new GroupingDataflowBlockOptions(){Greedy = true});
block.Target1.Post(1);
//block.Target2.Post(2);
var tuple = block.Receive();

有人可以向我解释为什么我需要向两个目标发布数据吗?

最佳答案

该 block 将接受一个目标的数据,但它不会传播数据,直到它可以形成一个元组。换句话说,您可以随心所欲地填充 target1,但如果 target2 中没有任何内容,您将永远不会得到任何内容。

如果您已将负载分布到多个连接 block ,贪婪行为可能会成为一个问题。一个 block 会吸收所有输入数据,而不让其他 block 有机会。

The use of non-greedy joins can also help you prevent deadlock in your application. In a software application, deadlock occurs when two or more processes each hold a resource and mutually wait for another process to release some other resource. Consider an application that defines two JoinBlock objects. Both objects each read data from two shared source blocks. In greedy mode, if one join block reads from the first source and the second join block reads from the second source, the application might deadlock because both join blocks mutually wait for the other to release its resource. In non-greedy mode, each join block reads from its sources only when all data is available, and therefore, the risk of deadlock is eliminated.

Source: How to: Use JoinBlock to Read Data From Multiple Sources

关于c# - 贪心 JoinBlock 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com