System.Threading.Tasks.Parallel error in IronRuby
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 3But, 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
17342
5
6 8What 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)
})
精彩评论