Re:A 1000-processor chip powered by an AA battery (2016)
by snak on Monday February 15, 2021 @10:30AM
(#26143602)
Yes, I do agree C# does have many constructs (Parallel For/ForEach/Invoke...) but there's many things to consider that are not designed with thread safety in mind (e.g. generic collections, List<T>, Dictionary<T>, etc... must be replaced by their System.Collections.Concurrent respectives) and many other risks that parallel computing poses.
int x = 0;
Parallel.For(0, 99999, z => {
x++;
});
Console.WriteLine(x);
Something as simple as an integer sum won't produce the expected output unless you're using Interlocked increments.And that definetely does not match what oblio means with "have the programming language Do The Right Thing with no further hassle".
Serial:
Parallel: In C# (https://docs.microsoft.com/en-us/dotnet/standard/parallel-pr...)Serial:
Parallel: (Function takes a lambda that gets called for each value)Swift has DispatchQueue.concurrentPerform (https://developer.apple.com/documentation/dispatch/dispatchq...). That is a bit less clear and less flexible (won’t iterate over an array’s values, only over its indexes) but also fairly easy to use.
There probably are many more languages with similar constructs.