writeFile/readFile on multiple threads leads to error

Neil Mitchell ndmitchell at gmail.com
Wed Apr 22 08:59:29 EDT 2009

Hi Claus,

>> do print ("READ START",x) ; res <- readFile x ; print ("READ STOP",x)
>> ; return res
> Unless you've defined your own version of 'readFile', to mean read
> entire file now, the first 'print' is optimistic and the second 'print' is a
> lie.

readFile calls openFile >>= hGetContents. It's the openFile that
causes the problem, so READ START happens before openFile and READ
STOP happens after openFile. The lazy semantics of the actual reading
don't seem to have an effect.

I did try changing to the strict bytestring file read, and that gave
exactly the same error - apart from openBinaryFile was crashing rather
than openFile.



>> do print ("WRITE START",x); writeFile x src ; print ("WRITE STOP",x)
>> I then get on the console:
>> openFile doesn't have permission to open foo.
>> The writeFile/readFile are happening in different threads, and they
>> usually succeed - but not always. The bug seems to go away when I add
>> performGC just after writeFile. My guess is that something in the
>> openFile/hClose pair isn't really closed until a garbage collection
>> happens. All this is using GHC 6.10.2 on XP through Cygwin.
>> I'm happy to supply more details if you can think of anything that will
>> help,
>> Thanks
>> Neil
>> _______________________________________________
>> Glasgow-haskell-users mailing list
>> Glasgow-haskell-users at haskell.org
>> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

More information about the Glasgow-haskell-users mailing list