LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1011|回复: 1

找不到读写锁的定义

[复制链接]
发表于 2008-4-27 21:05:53 | 显示全部楼层 |阅读模式
pthread_rwlock_t
pthread_rwlock_wrlock(pthread_rwlock_t *__rwlock)
pthread_rwlock_rdlock(pthread_rwlock_t *__rwlock)
pthread_rwlock_unlock(pthread_rwlock_t *__rwlock)

在我的debian stable(内核版本是 2.6.18-4-686)系统里引用上面的读写锁的类型和函数会导致编译通不过,但是在公司的debian testing系统里却没有任何问题,这是怎么回事?
我注意到了在pthreadtypes.h头文件中下面的定义:
  1. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  2. /* Read-write locks.  */
  3. typedef struct _pthread_rwlock_t
  4. {
  5.   struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
  6.   int __rw_readers;                   /* Number of readers */
  7.   _pthread_descr __rw_writer;         /* Identity of writer, or NULL if none */
  8.   _pthread_descr __rw_read_waiting;   /* Threads waiting for reading */
  9.   _pthread_descr __rw_write_waiting;  /* Threads waiting for writing */
  10.   int __rw_kind;                      /* Reader/Writer preference selection */
  11.   int __rw_pshared;                   /* Shared between processes or not */
  12. } pthread_rwlock_t;
  13. /* Attribute for read-write locks.  */
  14. typedef struct
  15. {
  16.   int __lockkind;
  17.   int __pshared;
  18. } pthread_rwlockattr_t;
  19. #endif
复制代码
在debian stable里__USE_UNIX98和__USE_XOPEN2K宏没有被定义吗?
发表于 2008-4-28 12:36:53 | 显示全部楼层
在我这里, __USE_UNIX98 是在 <features.h> 中定义的, 它在 _XOPEN_SOURCE >= 500 的时候被定义, 而 _XOPEN_SOURCE 在  _GNU_SOURCE 被定义的时候被定义

楼主 include <pthread.h> 之前定义一下 _GNU_SOURCE 或者 __USE_UNIX98 看看有什么效果?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表