Question

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?

Was it helpful?

Solution

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)
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top