2

例如,如果我有两个同时运行的进程并且它们都具有相同的代码

过程 1

1 Increase(x)
2 Decrease(x)

过程 2

1' Increase(x)
2' Decrease(x)

在该示例中,可能执行的次数为 6

在此处输入图像描述

我的问题是,当代码行和线程数不同时,是否存在可用于计算此执行次数的公式?
非常感谢

4

1 回答 1

1

enter image description here

This is a combination problem. Where n is (no of methods * no of processes) and k is no of methods.

So for your case n = (2 * 2) = 4 and k = 2

So answer will be = 4! / (2! 2!) = (4 * 3 * 2 * 1) / (2 * 2) = 6 and that's your answer from the diagram.

For more on Combination

于 2012-12-05T07:49:35.710 回答