NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | RESTRICTIONS | ERRORS | ATTRIBUTES
#include <exec/chExec.h>int threadSemInit(KnThSem * sem);
Thread semaphores are KnThSem structures allocated in user memory. A thread semaphore is a binary semaphore on which one, and only one, thread can wait, and which can be signalled to by multiple threads and/or interrupt handlers.
A thread semaphore can be in two states: POSTED and UNPOSTED.
The threadSemInit system call initializes the thread semaphore whose address is sem in the UNPOSTED state. The thread which performs threadSemInit on a given thread semaphore is the only thread which can wait on the semaphore (using threadSemWait ).
The threadSemWait system call makes the current thread wait conditionally on the thread semaphore sem. If the thread semaphore is in the POSTED state, threadSemWait returns immediately and atomically changes the state of the thread semaphore to UNPOSTED. If the thread semaphore is in the UNPOSTED state, the thread is blocked according to the options described by waitLimit in intro(2K). The waitLimit pointer points to a KnTimeVal structure containing a timeout interval as described in sysTime(2K).
The threadSemPost system call signals the thread semaphore sem. If the thread that initialized the thread semaphore is blocked behind the semaphore, threadSemPost awakens that thread without modifying the state of sem. If the thread is not blocked, threadSemPost sets the state of sem to POSTED. If the thread is not blocked and sem is already in the POSTED state, threadSemPost has no effect.
The threadSemPost system call may be called within an interrupt handler, or with preemption disabled.
Upon successful completion a value of 0 is returned. Otherwise, a negative error code is returned.
A user application and a supervisor application may not share a semaphore.
However, two user applications may share a semaphore by mapping it in both user address spaces.
threadSemWait has been aborted.
sem points outside the current actor's address space.
The thread semaphore structure has not been correctly initialized, or the waitLimit structure is not a valid KnTimeVal.
The timeout occurred.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | RESTRICTIONS | ERRORS | ATTRIBUTES