多线程编程指南

rwlock_init 语法

#include <synch.h>  (或  #include <thread.h>



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

type 可以是以下值之一:

同一个读写锁不能同时由多个线程初始化。读写锁还可以通过在清零的内存中进行分配来初始化,在这种情况下假设 type 为 USYNC_THREAD。对于其他线程可能正在使用的读写锁,不得重新初始化。

对于 POSIX 线程,请参见pthread_rwlock_init 语法

初始化进程内读写锁

#include <thread.h>



rwlock_t rwlp;

int ret;



/* to be used within this process only */

ret = rwlock_init(&rwlp, USYNC_THREAD, 0); 

初始化进程间读写锁

#include <thread.h>



rwlock_t rwlp;

int ret;



/* to be used among all processes */

ret = rwlock_init(&rwlp, USYNC_PROCESS, 0);