Chinaunix首页 | 论坛 | 博客
  • 博客访问: 278013
  • 博文数量: 46
  • 博客积分: 2021
  • 博客等级: 大尉
  • 技术积分: 406
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-03 13:00
文章分类

全部博文(46)

文章存档

2011年(1)

2010年(9)

2009年(2)

2007年(13)

2006年(21)

我的朋友

分类: 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

阅读(8325) | 评论(0) | 转发(0) |
0

上一篇:putty输入中文

下一篇:Pthread_create创建错误

给主人留下些什么吧!~~