Copyright | (c) The University of Glasgow 1994-2002 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | ghc-devs@haskell.org |
Stability | internal |
Portability | non-portable (GHC extensions) |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Basic concurrency stuff.
The API of this module is unstable and not meant to be consumed by the general public.
If you absolutely must depend on it, make sure to use a tight upper
bound, e.g., base < 4.X
rather than base < 5
, because the interface can
change rapidly without much warning.
Synopsis
- ensureIOManagerIsRunning :: IO ()
- ioManagerCapabilitiesChanged :: IO ()
- interruptIOManager :: IO ()
- threadDelay :: Int -> IO ()
- registerDelay :: Int -> IO (TVar Bool)
- threadWaitRead :: Fd -> IO ()
- threadWaitWrite :: Fd -> IO ()
- threadWaitReadSTM :: Fd -> IO (STM (), IO ())
- threadWaitWriteSTM :: Fd -> IO (STM (), IO ())
- closeFdWith :: (Fd -> IO ()) -> Fd -> IO ()
Documentation
ensureIOManagerIsRunning :: IO () Source #
interruptIOManager :: IO () Source #
Interrupts the current wait of the I/O manager if it is currently blocked. This instructs it to re-read how much it should wait and to process any pending events.
Since: base-4.15
Waiting
threadDelay :: Int -> IO () Source #
Suspends the current thread for a given number of microseconds (GHC only).
There is no guarantee that the thread will be rescheduled promptly when the delay has expired, but the thread will never continue to run earlier than specified.
Be careful not to exceed maxBound :: Int
, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.
Consider using Control.Concurrent.Thread.Delay.delay
from unbounded-delays
package.
registerDelay :: Int -> IO (TVar Bool) Source #
Switch the value of returned TVar
from initial value False
to True
after a given number of microseconds. The caveats associated with
threadDelay
also apply.
Be careful not to exceed maxBound :: Int
, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.
threadWaitRead :: Fd -> IO () Source #
Block the current thread until data is available to read on the given file descriptor (GHC only).
This will throw an IOError
if the file descriptor was closed
while this thread was blocked. To safely close a file descriptor
that has been used with threadWaitRead
, use closeFdWith
.
threadWaitWrite :: Fd -> IO () Source #
Block the current thread until data can be written to the given file descriptor (GHC only).
This will throw an IOError
if the file descriptor was closed
while this thread was blocked. To safely close a file descriptor
that has been used with threadWaitWrite
, use closeFdWith
.
threadWaitReadSTM :: Fd -> IO (STM (), IO ()) Source #
Returns an STM action that can be used to wait for data to read from a file descriptor. The second returned value is an IO action that can be used to deregister interest in the file descriptor.
threadWaitWriteSTM :: Fd -> IO (STM (), IO ()) Source #
Returns an STM action that can be used to wait until data can be written to a file descriptor. The second returned value is an IO action that can be used to deregister interest in the file descriptor.
:: (Fd -> IO ()) | Low-level action that performs the real close. |
-> Fd | File descriptor to close. |
-> IO () |
Close a file descriptor in a concurrency-safe way as far as the runtime
system is concerned (GHC only). If you are using threadWaitRead
or
threadWaitWrite
to perform blocking I/O, you must use this function
to close file descriptors, or blocked threads may not be woken.
Any threads that are blocked on the file descriptor via
threadWaitRead
or threadWaitWrite
will be unblocked by having
IO exceptions thrown.
Note that on systems that reuse file descriptors (such as Linux), using this function on a file descriptor while other threads can still potentially use it is always prone to race conditions without further synchronization.
It is recommended to only call
once no other threads can
use the given file descriptor anymore.closeFdWith