Lombiq/Hastlayer-SDK

Support Parallel.For()

Piedone opened this issue · 1 comments

So instead of e.g.:

for (int i = 0; i < MaxDegreeOfParallelism; i++)
{
    tasks[i] = Task.Factory.StartNew(
        indexObject =>
        {
            var index = (uint)indexObject;
            ...
        },
        i);
}

We'd write something like:

Parallel.For(0, MaxDegreeOfParallelism, index =>
{
    ...
});

This doesn't seem to be feasible. We somehow need to return results from the loop body: this is simple with Tasks but not with Parallel.For(). We'd need to either use shared state (and most possibly also add support for locks) or complicated constructs like the one explained here: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-write-a-parallel-for-loop-with-thread-local-variables