Safely writing to the same file in parallel foreach loop
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Wed Nov 14 08:43:26 PST 2012
On 11/14/2012 05:16 PM, H. S. Teoh wrote:
> If you're on Posix, you can use file locks to ensure atomic writes to
> the file (all threads have to use it though: it's only an advisory lock,
> not a mandatory lock): see the manpage for fcntl, look for F_GETLK.
I take it there's no more "native-to-D" way of implementing a file lock? :-(
I was browsing through the library descriptions of Mutex and ReadWriteMutex, but
it's not clear how they'd apply to this case (parallelism is really something I
have very limited experience of). I'm actually inclining towards an alternate
solution, where the different threads send back results to the master thread
which integrates them and writes out everything itself.
More information about the Digitalmars-d-learn
mailing list