[Haskell-cafe] Race conditions with threadWait(Read/Write) and closeFdWith

Felipe Lessa felipe.lessa at gmail.com
Tue Sep 2 17:31:33 UTC 2014


On 02-09-2014 14:01, John Lato wrote:
> Have you actually observed this behavior? I suspect that the thread will
> never yield between readMVar and threadWaitRead because there are no
> allocations.  I suppose an async exception could arise, so it might be
> correct to run that line with exceptions masked.

As I understand it, the problem isn't limited to the thread yielding.
If the program is running on more than one capability, it's conceivable
that another thread running on another capability will (a) close that Fd
and (b) open another Fd that will receive the same value, both between
the readMVar and the threadWaitRead calls.

I don't see how one could allow concurrent readers and "closers" without
leaving this small opening.  The best workaround I can think of is to
create a blocking close operation that waits for readers using a semaphore.

Cheers,

-- 
Felipe.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140902/30fa8212/attachment.sig>


More information about the Haskell-Cafe mailing list