分类: LINUX
2006-09-15 09:29:57
今天在程序里使用读写锁包括以下函数:
#include
int pthread_rwlock_rdlock(pthread_rwlock_t *rwptr);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwptr);
int pthread_rwlock_unlock(pthread_rwlock_t *rwptr);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwptr);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwptr);
int pthread_rwlock_init(pthread_rwlock_t *rwptr,
const pthread_rwlockattr_t *attr);
int pthread_rwlock_destroy(pthread_rwlock_t *rwptr);
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
int pthread_rwlockattr_destroy(pthread_rwlockattr_t * attr);
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * attr, int *valptr);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* attr, int value);
都返回:成功 0,出错为正的Exxxx值
测试程序如下:
#include
pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER;
int main()
{
return 0;
}
$ gcc –o lock lock.c
$ lock.c:2: parse error before `lock'
$ lock.c:2: `PTHREAD_RWLOCK_INITIALIZER' undeclared here (not in a function)
$ lock.c:2: warning: data definition has no type or storage class
最后查文档解决方是:
在程序开头加入:
#define _XOPEN_SOURCE 500