Safely writing to the same file in parallel foreach loop

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Nov 14 09:59:29 PST 2012


On 11/14/2012 06:49 PM, Vijay Nayar wrote:
> Could you put the file access in a synchronized block?
>
> http://dlang.org/statement.html#SynchronizedStatement

Oh, good call -- seems to work.

If you try and run the parallel code without it, there's a pretty nasty-looking 
error:

    /tmp/.rdmd-1000/rdmd-pforeach.d-7A1C6D0E6B47053236731E75615AD487/pforeach: 
double free or corruption (out): 0x00007f58bc000910 ***

... but with the synchronized {} block around the file append, all seems to work 
fine.


More information about the Digitalmars-d-learn mailing list