开发者

System.Threading.Tasks.Parallel error in IronRuby

开发者 https://www.devze.com 2023-04-06 19:02 出处:网络
In C# class ParallelTest { public static void Main() { System.Threading.Tasks.Parallel.ForEach(new []{1,2,3,4,5,6,7,8},

In C#

class ParallelTest
{
    public static void Main()
    {
        System.Threading.Tasks.Parallel.ForEach(new []{1,2,3,4,5,6,7,8},
                        x => { System.Console.WriteLine(x); }
                    );
    }
}

Result

4

5

6

7

8

2

1

3

But, in IronRuby(1.1.3).

Some line empty or lose linefeed.

System::Threading::Tasks::Parallel::ForEach([1,2,开发者_开发技巧3,4,5,6,7,8], Proc.new {|x|
    puts x;
})

Result

1734

2

5

6

8

What coused this problem?

Is this just a bug?


It seems IronRuby's puts is not thread-safe. If you use Console.WriteLine() in IR, it works fine:

System::Threading::Tasks::Parallel::ForEach([1,2,3,4,5,6,7,8], Proc.new {|x|
    System::Console::WriteLine(x)
})
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号