Multithreaded Programming Guide

Initialize a Readers/Writer Lock

rwlock_init(3T)

#include <synch.h>  (or #include <thread.h>)

int rwlock_init(rwlock_t *rwlp, int type, void * arg);

Use rwlock_init() to initialize the readers/writer lock pointed to by rwlp and to set the lock state to unlocked. type can be one of the following (note that arg is currently ignored).

Multiple threads must not initialize the same readers/writer lock simultaneously. Readers/writer locks can also be initialized by allocation in zeroed memory, in which case a type of USYNC_THREAD is assumed. A readers/writer lock must not be reinitialized while other threads might be using it.

Initializing Readers/Writer Locks with Intraprocess Scope

#include <thread.h>

rwlock_t rwlp;
int ret;

/* to be used within this process only */
ret = rwlock_init(&rwlp, USYNC_THREAD, 0); 

Initializing Readers/Writer Locks with Interprocess Scope

#include <thread.h>

rwlock_t rwlp;
int ret;

/* to be used among all processes */
ret = rwlock_init(&rwlp, USYNC_PROCESS, 0); 

Return Values

rwlock_init() returns zero after completing successfully. Any other returned value indicates that an error occurred. When any of the following conditions occur, the function fails and returns the corresponding value.


EINVAL

Invalid argument.


EFAULT

rwlp or arg points to an illegal address.