#include <exec/chExec.h>int threadSemInit(KnThSem * sem);
The function or functions documented here may not be used safely in all application contexts with all APIs provided in the ChorusOS 5.0 product.
See API(5FEA) for details.
Thread semaphores are KnThSem structures allocated in user memory. A thread semaphore is a binary semaphore for which one, and only one, thread can wait, and which receives signals from multiple threads 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 that performs threadSemInit() on a given thread semaphore is the only thread that can wait for the semaphore (using threadSemWait() ).
The threadSemWait() system call makes the current thread wait conditionally for 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.
threadSemPost() may be called within an interrupt handler, or with preemption disabled.
On 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.
The thread semaphore structure has not been correctly initialized, or the waitLimit structure is not a valid KnTimeVal .
A timeout occurred.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|