copyFile and thread safety
Neil Mitchell
ndmitchell at gmail.com
Mon Mar 30 08:31:54 EDT 2009
Hi,
Using GHC 6.8.3, the copyFile routine isn't thread safe - it crashes
when two threads try and open the same file. I think that improvements
were made to avoid security race conditions in GHC 6.10.1 (or the base
library associated with it), and as a nice side effect they seem to
have fixed the copyFile issues. However, it would be nice if someone
could assure me that the copyFile issues were real but are now fixed.
Replicating them is hard, but they randomly occur during a 1-hour
build on my laptop, but not my desktop.
I also note that copyFile starts with the process id and increments
looking for a free filename. While that's fantastic if you are
avoiding races with other processes (as I think the improvements were
intended to address), it's not so great for avoiding races within the
same process when different threads attempt to copy lots of files at
once. In doing this, I suspect I've suffered lots of retries in the
temporary name creation algorithm - should I be concerned about the
performance aspect of this? Would an atomicModifyIORef and global temp
file counter be a good idea?
For now, I've got no immediate problems as I simply shell out to "cp"
to do the copying - but it would be nice if the Haskell worked too.
Thanks
Neil
More information about the Glasgow-haskell-users
mailing list