| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Concurrent.CFuture
Description
Defines a type similar to C++ futures, that can be passed to C and used to interrupt asynchronous calls or to get their results.
From within Haskell, you can use
forkFuture to start a calculation,
get to wait on it
and abort to abort it.
From C, interruption happens via calling a C-native FFI function, without the cost of a full FFI call. See the C source for more information.
Synopsis
- data Future a
- type CFuturePtr = Ptr (StablePtr PrimMVar)
- forkFuture :: IO a -> IO (Future a)
- writeFutureC :: CFuturePtr -> Future a -> IO ()
- forkFutureC :: CFuturePtr -> IO a -> IO ()
- get :: Future a -> IO (Maybe a)
- getC :: Storable a => CFuturePtr -> Ptr a -> IO Bool
- waitC :: CFuturePtr -> IO Bool
- abort :: Future a -> IO Bool
Documentation
An object representing an asynchronous calculation. Filling the first MVar activates a thread that aborts the calculation and writes Nothing to the other MVar (which would otherwise contain the result). It is recommended not to manipulate the MVars directly, but to use the functions in the library instead.
type CFuturePtr = Ptr (StablePtr PrimMVar) Source #
Gets translated to HsStablePtr* (i.e. void**) in C.
forkFuture :: IO a -> IO (Future a) Source #
Starts an asynchronous calculation
and returns a Future to it.
writeFutureC :: CFuturePtr -> Future a -> IO () Source #
Creates StablePtrs
and writes them to a memory area
provided by a C caller.
Use this in functions where the C frontend provides
a CFuturePtr to write the future to.
Note: it is the responsibility of the C side
to free the StablePtrs.
forkFutureC :: CFuturePtr -> IO a -> IO () Source #
Similar to forkFuture, but
we write the Future into a location
given by the caller.
This makes it easier to create C exports
for actions.
Use this in functions where the C frontend provides
a CFuturePtr to write the future to.
Note: it is the responsibility of the C side
to free the StablePtrs.
getC :: Storable a => CFuturePtr -> Ptr a -> IO Bool Source #
A variant of get to call from C
which writes the result to the memory location
defined by the pointer.
If there is Nothing instead of a result,
it writes nothing to the pointer
and returns False;
on success, it returns True.
Note: do _not_ call this on a freed Future
(the abortC function of the C side frees it).