Is this a good idea?

Dr.No jckj33 at gmail.com
Thu Aug 30 19:59:17 UTC 2018


I would to process the current block in parallel but priting need 
to be theread-safe so I'm using

> foreach(x; parallel(arr)) {
>    auto a = f(x);
>    auto res = g(a);
>    synchronized {
>	stdout.writeln(res);
>	stdout.flush();
>     }
> }


Since f() and g() are some heavy functions, I'd like to process 
in parallel but the printing (doesn't need to respect order but 
must be thread-safe) hence I'm using synchronized. Is this 
counter-productive in any way?


More information about the Digitalmars-d-learn mailing list