[Haskell-cafe] getContents and lazy evaluation
donn at drizzle.com
Fri Sep 1 23:27:56 EDT 2006
Quoth Julien Oster <haskell at lists.julien-oster.de>:
| But what happens when two processes use the same file and one process is
| writing into it using lazy IO which didn't happen yet? The other process
| wouldn't see its changes yet.
That's actually a much more general problem, one that I imagine applies
to hPutStr et al. too. Application level writes are ordinarily buffered
in process space by the I/O library, so output from an ordinary C program
may not appear on disk (or in kernel space disk I/O buffer) until just
before the program exits.
| As for two processes writing to the same file at the same time, very bad
| things may happen anyway. Sure, lazy IO prevents doing communication
| between running processes using plain files, but why would you do
| something like that?
Quite a few reasons, depending on how you define communication. You
might even be tempted to use hGetContents in such cases. For example,
one common way to share a file is to interlock around some resource,
and when you acquire the lock, you read the file (get its contents)
and release the lock.
Donn Cave, donn at drizzle.com
More information about the Haskell-Cafe