GHC.IO.Device and "ready" method?

Hi, 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? Thanks. -- Dimitry Golubovsky Anywhere on the Web

Hello Dimitry, Friday, June 25, 2010, 7:06:31 PM, you wrote:
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 think so. i consider threads as control structure and your question looks for me the as "can we use Handle in function/cycle other that one created it" in particular, it was always safe to make I/O from many threads for the same Handle -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

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
participants (3)
-
Bulat Ziganshin
-
Dimitry Golubovsky
-
Simon Marlow