Results are undefined if any of these functions are called with an uninitialized read-write lock.行为是未定义的。所以不应该是去深究背后的为什么。当然如果还是有兴趣去钻研下,就针对你用到的实现版本,去看看实现逻辑是什么样的。但个人不建议去深究,因为研究出来的结论也是没有太多意义的。
Next: 获取读锁 初始化读写锁使用rwlock_init(3C) 可以初始化 rwlp 所指向的读写锁并将锁的状态设置为未锁定。rwlock_init 语法#include <synch.h> (或 #include <thread.h>) int rwlock_init(rwlock_t *rwlp, int type, void * arg);type
使用pthread_rwlock_init(3C) 可以通过 attr 所引用的属性初始化 rwlock 所引用的读写锁。pthread_rwlock_init 语法#include <pthread.h> int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;...