IronRuby中的System.Threading.Tasks.Parallel错误

时间:2011-09-22 01:11:48

标签: c# .net parallel-processing ironruby

在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); }
                    );
    }
}

结果
4
5
6
7
8
2
1
3

但是,在IronRuby(1.1.3)中 有些行空了或丢失了换行符。

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

结果
1734

2

5
6
8

是什么解决了这个问题? 这只是一个错误吗?

1 个答案:

答案 0 :(得分:2)

似乎IronRuby的puts不是线程安全的。如果你在IR中使用Console.WriteLine(),它可以正常工作:

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