Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 8

SyncTypeCreate(), SyncTypeCreate_r()

Create a synchronization object

Synopsis:

#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 );

Arguments:

type
One of the following:
sync
A pointer to a sync_t that the kernel sets up for the synchronization object; see below.
attr
A pointer to a _sync_attr_t structure that specifies attributes for the object. This structure contains at least the following members:

If attr is NULL, the default attributes (PTHREAD_PRIO_INHERIT) are assumed.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.


Caution: You should allocate synchronization objects only in normal memory mappings. On certain processors (e.g. some PPC ones), atomic operations such as calls to pthread_mutex_lock() will cause a fault if the control structure is allocated in uncached memory.

Synchronization objects can be used for mutexes, semaphores, or condition variables.


Note: 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_t argument contains at least the following members:

int __count
The count for recursive mutexes and semaphores. The kernel sets this member when it creates the synchronization object.
int __owner
When a mutex is created, this member holds the thread ID of the thread that acquired the mutex. When unowned, the value is 0. It's set to zero when the synchronization object is created.

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().

Blocking states

These calls don't block.

Returns:

The only difference between these functions is the way they indicate errors:

SyncTypeCreate()
If an error occurs, the function returns -1 and sets errno. Any other value returned indicates success.
SyncTypeCreate_r()
Returns EOK on success. This function does NOT set errno. If an error occurs, the function can return any value in the Errors section.

Errors:

EAGAIN
All kernel synchronization objects are in use.
EFAULT
A fault occurred when the kernel tried to access sync or attr.
EINVAL
Either

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

pthread_cond_init(), pthread_mutex_init(), pthread_rwlock_init(), sem_init(), SyncCondvarSignal(), SyncCondvarWait(), SyncDestroy(), SyncMutexLock(), SyncMutexUnlock()

Synchronization services in the QNX Neutrino Microkernel chapter of the System Architecture guide


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 363

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/synctypecreate.html on line 363