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

Felipe Lessa felipe.lessa at gmail.com
Wed Sep 3 17:57:35 UTC 2014


On 03-09-2014 14:40, Leon Smith wrote:
> I think the semantics should probably be for a concurrent close to
> immediately close the descriptor,  with exceptions raised in any threads
> that are blocked on the descriptor.    It seems that any sort of
> use-case along these lines is going to result in an exception
> eventually... so you might as well make it prompt.     So I still don't
> see any lock-based solution for my intended semantics.

How far are you willing to go? :)

Instead of an Int, you could use [ThreadId] as a set (or any other data
structure).  The only problem I can see with this approach is:

  - Thread A adds itself to the [ThreadId] and waits for the Fd.

  - Thread B starts closing the Fd.

  - Thread A is awakened from the Fd.

  - Thread B closes the Fd and sends async exceptions to all [ThreadId],
including thread A.

  - Thread A tries to modify the [ThreadId] again to remove itself, but
sees Nothing instead.

At this point, thread A has not yet received the async exception, but it
*knows* that the exception is coming!  Poor thread A :(.

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/20140903/09817270/attachment.sig>


More information about the Haskell-Cafe mailing list