pthread_rwlock_t 结构体的定义:
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned char __flags;
unsigned char __shared;
unsigned char __pad1;
unsigned char __pad2;
int __writer;
} __data;
endif
char __size[__SIZEOF_PTHREAD_RWLOCK_T];
long int __align;
} pthread_rwlock_t;
在多线程编程中,死锁问题是比较难定位的一种,通过调用栈我们查看此时的pthread_rwlock_t信息,对我们定位问题的帮助是很大的。
我们通常关注的字段有:
__nr_readers,
__nr_readers_queued,
__nr_writers_queued,
__writer
那这四个字段,那当我们线程加锁时,是怎么反应并记录到这个结构体中的呢?
当我们使用pthread_rwlock_rdlock()获取一次读锁时,__nr_rea