【问题标题】:System.Threading.Tasks.Parallel error in IronRubyIronRuby 中的 System.Threading.Tasks.Parallel 错误
【发布时间】:2011-09-22 01:11:48
【问题描述】:

在 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

是什么导致了这个问题?
这只是一个错误吗?

【问题讨论】:

    标签: c# .net parallel-processing ironruby


    【解决方案1】:

    看来 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)
    })
    

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多