Re:Concurrency I can finally understand and write correctly
by jordigh on Monday March 12, 2018 @11:05AM
(#16568592)
Concurrency isn't the same thing as parallelism. You can have concurrency without ever executing two things at the same time. You just give some CPU cycles to one threaad, then pause it, give cycles to the other thread, and keep switching back and forth. Indeed, this is what any multitasking operating system has always done, even when every computer only had one CPU.
For parallelism as what you describe, D instead has approximately the same thing. There's a `parallel` function in the standard library that works on any range (i.e. any iterable). You basically instead of doing
foreach(object; somerange) {
// ..
}
do foreach(object; parallel(somerange)) {
// ...
}
and it works like your Perl example.If you want it more functionalish, without writing out the loop, you can use `taskPool.map` instead of ordinary `map` for the same effect. More details:
stdlib: https://dlang.org/phobos/std_parallelism.html
Programming in D chapter on parallelism: http://ddili.org/ders/d.en/parallelism.html
Re:Concurrency I can finally understand and write correctly
by kqr on Monday March 12, 2018 @01:11PM
(#16569600)
Is this more than just flat data parallelism, in any way? Honest question!
Re:Concurrency I can finally understand and write correctly
by zzzcpan on Monday March 12, 2018 @11:09AM
(#16568625)
Concurrency is not a first class citizen in Perl 6 though. As with Perl 5 the best you can hope for is actor model implemented on top of promises/futures.
Re:Concurrency I can finally understand and write correctly
by zoffix222 on Monday March 12, 2018 @11:27AM
(#16568756)
What would make it a first-class citizen?
Even an empty Rakudo Perl 6 program is a multi-threaded program, as the dynamic optimizer runs on a separate thread. I'd figure if that's possible, concurrency/parallelism would be quite a first-class citizen, not a best hope on top of something.
Especially the .hyper method that turns a regular sequence into hyper sequence that gets processed in parallel. First 5000 prime numbers: