下面是我的实现方式,如果不对。请大家指正!
首先,我百度了一个测试用例:
class Test
{
private :
rw_lock rw;
pthread_rwlock_t rwlock;
static void* shared_task_handler(void* arg)
{
Test* testptr = static_cast<Test*>(arg);
//pthread_rwlock_rdlock(&testptr->rwlock);
testptr->rw.lock_read();
// do the shared task here
pthread_mutex_lock(&cout_lock);
cout << "read---count = " << count << endl;
pthread_mutex_unlock(&cout_lock);
/*if (pthread_rwlock_unlock(&testptr->rwlock) )
{
cout << "read unlock error " << endl;
}*/
testptr->rw.unlock_read();
return NULL;
}
static void * exclusive_task_handler(void * arg)
{
Test* testptr = static_cast<Test*>(arg);
//pthread_rwlock_wrlock(&testp