[project @ 1999-07-05 19:26:42 by sof]
authorsof <unknown>
Mon, 5 Jul 1999 19:26:42 +0000 (19:26 +0000)
committersof <unknown>
Mon, 5 Jul 1999 19:26:42 +0000 (19:26 +0000)
commit60e60f66152de66f31d59f9a2c720552d13c0372
tree5fe46ba451f943a0bbd30cf2af98a6ca07053ec3
parent2455da3a4d8f50e6eb6d033dcfda2c8467bfd8cd
[project @ 1999-07-05 19:26:42 by sof]
Temporary workaround for problem which caused the following program

  main = putStrLn ("aa" ++ IOExts.trace "bb" "cc")

to deadlock - when the (untouched) stderr is evaluated (which
IOExts.trace forces), it will touch stdout (see code for details of
why), but it has already been locked by putStrLn. Boom - game over.

This temporary 'fix' is, to put it kindly, in the fancy-footwork
category as it doesn't solve the problem, but merely turns it on its
head. Instead of stderr depending on stdout, stdout now depends on
stderr, so the following program will deadlock

  main = hPutStrLn stderr ("aa" ++ myTrace "bb" "cc")

  myTrace msg v = unsafePerformIO $ do
     putStrLn msg
     return v

The 'theory' is that this is far less likely to occur in practice than
the other way around.

The next step / real solution would be to give up the lock on an
output Handle while filling up its output buffer. However, that
requires ripping out / re-org'ing a fair bit of buffer management
code, which I'll delay doing.
ghc/lib/std/PrelHandle.lhs