Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AsParallel crashing a MonoTouch app

MonoTouch advertises support for AsParallel on its website with this code snippet:

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

However, even a trivial sample crashes my app:

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

System.ExecutionEngineException has been thrown. Attempting to JIT compile method 'System.Linq.Parallel.QueryNodes.WrapHelper:<Wrap<code>1>m__4A<int>(System.Collections.Generic.IEnumerator</code>1<int>)' while running with --aot-only.

I know MonoTouch can't handle virtual generic methods but isn't PLINQ supposed to work?
What is it wrong that I am doing?

MonoTouch version is 5.3.5.

Same goes for 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.
like image 370
Dan Abramov Avatar asked Oct 07 '22 22:10

Dan Abramov


1 Answers

This is a known limitation with MonoTouch and generics - in this case it's because you're working with structures.

It should work if you use objects instead:

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

We're working on fixing some of these limitations, so it would be nice if you could file a bug report with a sample project for us to have a look to see if it is possible to actually fix this case on day.

like image 167
Rolf Bjarne Kvinge Avatar answered Oct 10 '22 03:10

Rolf Bjarne Kvinge