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?

Reply via email to