GHC.IO.Device and "ready" method?

Simon Marlow marlowsd at gmail.com
Tue Jun 29 17:00:41 EDT 2010


On 25/06/10 16:06, Dimitry Golubovsky wrote:
> Should an implementation of GHC.IO.Device expect the `ready' method to
> be called from a thread different than one waiting for an I/O
> operation on a handle to complete, while that operation is in
> progress?
>
> As a more general question, are GHC Handles (and underlying
> implementations of GHC.IO.Device and GHC.IO.BufferedIO) expected to be
> thread-safe?
>
> I would be happy to store the id of the thread that calls mkFileHandle
> somewhere in the underlying `dev' and simply reject all I/O requests
> that come from other threads, but is this correct/permitted behavior?

The Handle layer implements its own mutual exclusion (a Handle is an 
MVar), so you only need to worry about thread-safety for your device if 
you expose it some other way, or make it accessible from multiple 
Handles.  FD for example does no additional locking.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list