This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Create a synchronization object
#include <sys/neutrino.h> int SyncTypeCreate( unsigned type, sync_t * sync, const struct _sync_attr_t * attr ); int SyncTypeCreate_r( unsigned type, sync_t * sync, const struct _sync_attr_t * attr );
If attr is NULL, the default attributes (PTHREAD_PRIO_INHERIT) are assumed.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The SyncTypeCreate() and SyncTypeCreate_r() kernel calls create a synchronization object in the kernel and initializes sync for use in other synchronization kernel calls. The synchronization object is local to the process.
These functions are similar, except for the way they indicate errors. See the Returns section for details.
Synchronization objects can be used for mutexes, semaphores, or condition variables.
Don't call SyncTypeCreate() directly; instead, use the POSIX synchronization objects (see pthread_cond_init(), pthread_mutex_init(), pthread_rwlock_init(), and sem_init()). |
The sync argument contains at least the following members:
The current state of sync is summarized below:
Counter | Owner | Description |
---|---|---|
-- | -2 | Destroyed mutex |
0 | -1 | Statically initialized; auto-created when used |
0 | 0 | Unlocked mutex |
count | >0 | Recursive counter number of the mutex |
count | <-1 | If the high bit of count is set, it's a flag meaning "others waiting" |
-- | -256 | Mutex is dead, waits for revival |
The synchronization object is destroyed by a call to SyncDestroy().
These calls don't block.
The only difference between these functions is the way they indicate errors:
Or:
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pthread_cond_init(), pthread_mutex_init(), pthread_rwlock_init(), sem_init(), SyncCondvarSignal(), SyncCondvarWait(), SyncDestroy(), SyncMutexLock(), SyncMutexUnlock()