【问题标题】:AsParallel crashing a MonoTouch appAsParallel 使 MonoTouch 应用程序崩溃
【发布时间】:2012-08-14 18:45:23
【问题描述】:

MonoTouch advertises 在其网站上支持AsParallel,代码如下:sn-p:

from item in items.AsParallel ()
   let result = DoExpensiveWork (item)
   select result;

但是,即使是一个微不足道的示例也会使我的应用崩溃:

 var items = new [] { 1, 2, 3 };
 var twice = (
        from x in items.AsParallel()
        select 2 * x
    ).ToArray();

我知道 MonoTouch 无法处理虚拟泛型方法,但 PLINQ 不应该工作吗?
我做错了什么?

MonoTouch 版本是 5.3.5。

Parallel.ForEach 也是如此:

System.AggregateException: One or more errors occured ---> System.Exception:
Attempting to JIT compile method 'System.Threading.Tasks.Parallel:<ForEach`1>m__36<int> ()' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.

【问题讨论】:

  • @James:AFAIK --aot-only 是真实 iOS 设备上唯一可能的模式,因为 Apple 禁止 JIT。
  • 这可能是一个错误,在这里报告,并附上一个快速项目来重现它:bugzilla.xamarin.com

标签: c# xamarin.ios task-parallel-library plinq


【解决方案1】:

This is a known limitation with MonoTouch and generics - 在这种情况下,这是因为您正在使用结构。

如果你使用对象,它应该可以工作:

var items = new object [] { 1, 2, 3 };
var twice = (
    from x in items.AsParallel()
    select 2 * x
).ToArray();

我们正在努力修复其中的一些限制,因此如果您可以提交包含示例项目的错误报告,以便我们查看是否有可能在当天实际修复此案例,那就太好了。

【讨论】:

  • 感谢您的回答。我现在明白应该归咎于结构。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
  • 2011-05-31
  • 2017-11-10
相关资源
最近更新 更多