[Haskell-cafe] Opening the same file multiple times
duncan.coutts at worc.ox.ac.uk
Mon Dec 12 07:06:52 EST 2005
On Mon, 2005-12-12 at 07:43 +0200, Einar Karttunen wrote:
> It seems that opening the same file multiple times (one writer
> and multiple readers) is not supported at least on *nix with
> GHC. I want to use one Handle to use append data till the
> end of the file while other Handles perform random access
> IO with seeks on the file.
It states in the Haskell Report 21.2.3:
Implementations should enforce as far as possible, at least
locally to the Haskell process, multiple-reader single-writer
locking on files. That is, there may either be many handles on
the same file which manage input, or just one handle on the file
which manages output. If any open or semi-closed handle is
managing a file for output, no new handle can be allocated for
that file. If any open or semi-closed handle is managing a file
for input, new handles can only be allocated if they do not
manage output. Whether two files are the same is
implementation-dependent, but they should normally be the same
if they have the same absolute path name and neither has been
renamed, for example.
So yes, what you're trying to do is not supported by the standard IO
library. GHC is doing the right thing and hugs is not.
I'm not sure which layer implements the file locking so it may be that
you can get underneath by using the System.Posix.IO functions.
More information about the Haskell-Cafe