Table 11-2. Synchronization Services
Sync Mechanism | Implemented in | Used by | POSIX |
---|---|---|---|
Semaphore | Kernel | Process/Threads | YES |
Mutexes | Kernel | Threads | YES |
Recursive Mutexes | Kernel | Threads | YES |
Condition variable | External Process | Threads | YES |
Readers/Writers locks | External Process | Threads | YES |
Barriers | External Process | Threads | YES |
FIFO scheduling | Kernel | Process/Threads | NO |
Atomic operations | Kernel | Process/Threads | NO |
Table 11-3. Communication Services
Communication Mechanism | Implemented in | Used by | POSIX |
---|---|---|---|
Message Passing | kernel | Processes | NO |
Signals | -- | Processes/Threads | YES |
PIPES | external process | Processes/Threads | YES |
FIFOs | external process | Processes/Threads | YES |
Message Queues | external process | Threads | YES |
Shared Memory | process manager | Processes/Threads | YES |
QNX provides the full-POSIX semaphores calls. Therefore, both named and unamed semaphores are provided.
The following table list the primitives available on QNX for managing the semaphores, as well as, the microkernel calls used by these routines:
Table 11-4. Semaphore management primitives
POSIX Call | Kernel Call | Description |
---|---|---|
sem_init() | SyncTypeCreate() | Creates a semaphore |
sem_destroy() | SyncDestroy() | Destroy synchronization object |
sem_wait() | SyncSemWait() | Wait on a semaphore |
sem_trywait() | SyncSemWait() | Wait on a semaphore |
sem_post() | SyncSemPost() | Post a semaphore |
Table 11-5. Mutexes management primitives
POSIX Call | Kernel Call | Description |
---|---|---|
pthread_mutex_init() | SyncTypeCreate() | Create a mutex. |
pthread_mutex_destroy() | SyncDesctroy() | Destroy a mutex. |
pthread_mutex_lock() | SyncMutexLock() | Lock a mutex. |
pthread_mutex_unlock() | SyncMutexUnlock() | Unlock a mutex. |
pthread_mutex_trylock() | SyncMutexLock() | Used to test whether the mutex is currently locked or not. |
The following mutex types are supported by QNX: PTHREAD_MUTEX_NORMAL,PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE and PTHREAD_MUTEX_DEFAULT. Note that QNX supports the full POSIX mutex types.
Currently, there is only one POSIX mutex protocol available in QNX: the PTHREAD_PRIO_INHERIT protocol. Therefore, PTHREAD_PRIO_PROTECT protocol is not supported.
Finally, it is important to note how the classic priority inversion problem is solved: If a thread with a higher priority than the mutex owner tries to lock a mutex, then the effective priority of the current owner will be increased to that of the higher priority blocked thread waiting for mutex. The owner will returns to its real priority when it unlocks the mutex. This scheme is called priority inheritance.
Table 11-6. Atomic Operations
Function | Description |
---|---|
atomic_add() | Add a value. |
atomic_sub() | Substract a value. |
atomic_clr() | Clear bits. |
atomic_set() | Set bits. |
atomic_toggle() | Complementing bits. |
The following illustration shows the state changes in a send-receive transaction.
The following table lists the message passing API provided by QNX:
Table 11-7. Message Passing API
Function | Description |
---|---|
MsgSend() | Send a message and block until reply. |
MsgReceive() | Wait for a message. |
MsgReceivePulse() | Wait for a tiny, nonblocking message (pulse). |
MsgReply() | Reply to a message. |
MsgError() | Reply only with an error status. No message bytes are transferred. |
MsgRead() | Read additional data from a received message. |
MsgWrite() | Write additional data to a reply message. |
MsgInfo() | Obtain info on a received message. |
MsgSendPulse() | Send a tiny, nonblocking message (pulse). |
MsgDeliverEvent() | Deliver an event to a client. |
MsgKeyData() | Key a message to allow security checks. |
Moreover, QNX provides other message passing functions and mechanism that are based on the API defined above. This mechanism are: Multipart Transfers, Channels and Pulses.
Table 11-8. Signals range
Signal range | Description |
---|---|
1...57 | 57 POSIX signals, including traditional UNIX signals. |
41...56 | 16 POSIX realtime signals. |
57...64 | 8 special Neutrino signals. |
To uses pipes in QNX, the pipe resource manager, called pipe must be loaded.
As well as pipes, for using FIFOs in QNX, the resource manager pipe must be loaded.