unix-2.6.0.1: POSIX functionality

Portability | non-portable (requires POSIX)
Stability | experimental
Maintainer | libraries@haskell.org
Safe Haskell | Trustworthy

System.Posix.Semaphore

Description

POSIX named semaphore support.

Synopsis

- data OpenSemFlags = OpenSemFlags {
  - semCreate :: Bool
  - semExclusive :: Bool
  }
- data Semaphore
- semOpen :: String -> OpenSemFlags -> FileMode -> Int -> IO Semaphore
- semUnlink :: String -> IO ()
- semWait :: Semaphore -> IO ()
- semTryWait :: Semaphore -> IO Bool
- semThreadWait :: Semaphore -> IO ()
- semPost :: Semaphore -> IO ()
- semGetValue :: Semaphore -> IO Int

# Documentation

data OpenSemFlags

Constructors

OpenSemFlags |
Fields semCreate :: Bool If true, create the semaphore if it does not yet exist. semExclusive :: Bool If true, throw an exception if the semaphore already exists.

data Semaphore

semOpen :: String -> OpenSemFlags -> FileMode -> Int -> IO Semaphore

Open a named semaphore with the given name, flags, mode, and initial value.

semUnlink :: String -> IO ()

Delete the semaphore with the given name.

semWait :: Semaphore -> IO ()

Lock the semaphore, blocking until it becomes available. Since this is done through a system call, this will block the *entire runtime*, not just the current thread. If this is not the behaviour you want, use semThreadWait instead.

semTryWait :: Semaphore -> IO Bool

Attempt to lock the semaphore without blocking. Immediately return False if it is not available.

semThreadWait :: Semaphore -> IO ()

Poll the semaphore until it is available, then lock it. Unlike semWait, this will block only the current thread rather than the entire process.

semPost :: Semaphore -> IO ()

Unlock the semaphore.

semGetValue :: Semaphore -> IO Int

Return the semaphore's current value.