小编Bar*_*ski的帖子

如何对同一阵列中的随机位置执行多线程操作?

我有一个进程在随机位置上运行大量任务,Array并希望通过使用多线程来加快速度.

它本质上做的是随机化"阵列"中的位置,检查其近似环境的值,并在满足一些特定条件时改变随机位置值.

是否有可能运行像

Parallel.For(0, n, s => { });
Run Code Online (Sandbox Code Playgroud)

循环而不是下面显示的while代码块来优化这个函数,一个代码块怎么样呢?

我一直在考虑为所选元素使用一些"忙"属性,但这实际上使得问题可能需要更加复杂.

public void doStuffTothisArray(ref int[,,] Array, ref IGenerator randomGenerator, int loops)
{
    int cc = 0;
    int sw = 0;
    do
    {
        if (doStuffOnRandomPositions(ref Array, ref randomGenerator))
            sw++; //if stuff was made counter

        if ((cc % (loops / 10)) == 0)
            Console.Write("{0} % \t", (cc / (loops / 10)) * 10); //some loading info

        cc++; //count iterations
    } while (cc < loops);
    Console.WriteLine("Stuff altered in {0} iterations: {1}", …
Run Code Online (Sandbox Code Playgroud)

c# arrays random parallel-processing multithreading

4
推荐指数
1
解决办法
128
查看次数

标签 统计

arrays ×1

c# ×1

multithreading ×1

parallel-processing ×1

random ×1