Copyright | (c) 2019 Composewell Technologies |
---|---|
License | BSD3 |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Streamly.Internal.Data.IORef
Description
A mutable variable in a mutation capable monad (IO) holding a Unboxed
value. This allows fast modification because of unboxed storage.
Multithread Consistency Notes
In general, any value that straddles a machine word cannot be guaranteed to
be consistently read from another thread without a lock. GHC heap objects
are always machine word aligned, therefore, a IORef
is also word aligned.
On a 64-bit platform, writing a 64-bit aligned type from one thread and
reading it from another thread should give consistent old or new value. The
same holds true for 32-bit values on a 32-bit platform.
Synopsis
- data IORef a
- newIORef :: Unbox a => a -> IO (IORef a)
- writeIORef :: Unbox a => IORef a -> a -> IO ()
- modifyIORef' :: Unbox a => IORef a -> (a -> a) -> IO ()
- readIORef :: Unbox a => IORef a -> IO a
- pollGenericIORef :: forall (m :: Type -> Type) a. (MonadIO m, Unbox a) => IORef a -> Stream m a
- pollIORefInt :: forall (m :: Type -> Type). MonadIO m => IORef Int -> Stream m Int
Documentation
modifyIORef' :: Unbox a => IORef a -> (a -> a) -> IO () Source #
Modify the value of an IORef
using a function with strict application.
Pre-release
pollGenericIORef :: forall (m :: Type -> Type) a. (MonadIO m, Unbox a) => IORef a -> Stream m a Source #
Internal, do not use.
pollIORefInt :: forall (m :: Type -> Type). MonadIO m => IORef Int -> Stream m Int Source #
Generate a stream by continuously reading the IORef.
This operation reads the IORef without any synchronization. It can be assumed to be atomic because the size fits into machine register size. We are assuming that compiler uses single instructions to access the memory. It may read stale values though until caches are synchronised in a multiprocessor architecture.
Pre-release