Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2094042
  • 博文数量: 361
  • 博客积分: 10828
  • 博客等级: 上将
  • 技术积分: 4161
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-20 14:34
文章分类

全部博文(361)

文章存档

2011年(132)

2010年(229)

分类: C/C++

2011-09-22 10:27:29

需要包涵的头文件,编译时需要加-pthread。
#include
 
  1. 1、int pthread_equal(pthread_t t1, pthread_t t2);
  2.     返回值:相等不为0,否则为0.

  3. 2、pthread_t pthread_self(void);
  4.     返回值:函数执行总是成功,返回线程ID

  5. 3、int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  6.                           void *(*start_routine) (void *), void *arg);
  7.     返回值:成功返回0,否则返回错误编号

  8. 4、void pthread_exit(void *retval);

  9. 5、int pthread_join(pthread_t thread, void **retval);
  10.     返回值:成功返回0,否则返回错误编号

  11. 6、int pthread_cancel(pthread_t thread);
  12.     返回值:成功返回0,否则返回错误编号

  13. 7、void pthread_cleanup_push(void (*routine)(void *),void *arg);
  14.    void pthread_cleanup_pop(int execute);
  15.    
  16. 8、int pthread_detach(pthread_t thread);
  17.     返回值:成功返回0,否则返回错误编号

  18. /************************* 互斥体 ************************************/
  19. 9、int pthread_mutex_init(pthread_mutex_t *restrict mutex,
  20.               const pthread_mutexattr_t *restrict attr);
  21.    int pthread_mutex_destroy(pthread_mutex_t *mutex);
  22.     返回值:成功返回0,否则返回错误编号

  23. 10、int pthread_mutex_lock(pthread_mutex_t *mutex);
  24.     int pthread_mutex_trylock(pthread_mutex_t *mutex);
  25.     int pthread_mutex_unlock(pthread_mutex_t *mutex);
  26.     返回值:成功返回0,否则返回错误编号
  27.     
  28. /************************* 读写锁 ************************************/
  29. 11、int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
  30.     int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
  31.                 const pthread_rwlockattr_t *restrict attr);
  32.     返回值:成功返回0,否则返回错误编号

  33. 12、int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
  34.     int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
  35.     返回值:成功返回0,否则返回错误编号

  36. 13、int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
  37.     int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
  38.     返回值:成功返回0,否则返回错误编号

  39. 14、int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
  40.     返回值:成功返回0,否则返回错误编号

  41. /************************* 条件变量 ************************************/
  42. 15、int pthread_cond_destroy(pthread_cond_t *cond);
  43.     int pthread_cond_init(pthread_cond_t *restrict cond,
  44.           const pthread_condattr_t *restrict attr);
  45.     返回值:成功返回0,否则返回错误编号

  46. 16、int pthread_cond_timedwait(pthread_cond_t *restrict cond,
  47.           pthread_mutex_t *restrict mutex,
  48.           const struct timespec *restrict abstime);
  49.     int pthread_cond_wait(pthread_cond_t *restrict cond,
  50.           pthread_mutex_t *restrict mutex);
  51.     返回值:成功返回0,否则返回错误编号

  52. 17、通知条件满足
  53.     int pthread_cond_broadcast(pthread_cond_t *cond);
  54.     int pthread_cond_signal(pthread_cond_t *cond);
  55.     返回值:成功返回0,否则返回错误编号
  1. /************************* 线程属性 ************************************/
  2. 18、int pthread_attr_init(pthread_attr_t *attr);
  3.     int pthread_attr_destroy(pthread_attr_t *attr);
  4.     返回值:成功返回0,否则返回错误编号

  5. 19、设置获取分离(detach)属性
  6.     int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
  7.     int pthread_attr_getdetachstate(pthread_attr_t *attr, int *detachstate);
  8.     返回值:成功返回0,否则返回错误编号

  9. 20、设置获取线程栈属性
  10.     int pthread_attr_setstack(pthread_attr_t *attr,
  11.                                      void *stackaddr, size_t stacksize);
  12.     int pthread_attr_getstack(pthread_attr_t *attr,
  13.                              void **stackaddr, size_t *stacksize);
  14.     返回值:成功返回0,否则返回错误编号

  15. 21、设置获取线程栈默认大小
  16.     int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
  17.     int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize);
  18.     返回值:成功返回0,否则返回错误编号

  19. 22、设置获取线程栈警戒缓冲区大小
  20.     int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
  21.     int pthread_attr_getguardsize(pthread_attr_t *attr, size_t *guardsize);
  22.     返回值:成功返回0,否则返回错误编号

  23. 23、int pthread_setconcurrency(int new_level);
  24.     返回值:成功返回0,否则返回错误编号
  25.     int pthread_getconcurrency(void);
  26.     返回值:当前的并发度
  1. /************************* 互斥量属性 ************************************/
  2. 24、int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
  3.     int pthread_mutexattr_init(pthread_mutexattr_t *attr);
  4.     返回值:成功返回0,否则返回错误编号

  5. 25、设置获取共享互斥量属性,线程间为:PTHREAD_PROCESS_PRIVATE,进程间为:PTHREAD_PROCESS_SHARED
  6.     int pthread_mutexattr_getpshared(const pthread_mutexattr_t *
  7.                   restrict attr, int *restrict pshared);
  8.     int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
  9.           int pshared);
  10.     返回值:成功返回0,否则返回错误编号

  11. 26、设置获取共享互斥量类型
  12.     (PTHREAD_MUTEX_NORMAL(普通),PTHREAD_MUTEX_ERRORCHECK(带错误检测),
  13.     PTHREAD_MUTEX_RECURSIVE(递归),PTHREAD_MUTEX_DEFAULT(默认))
  14.     int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
  15.                   int *restrict type);
  16.     int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
  17.     返回值:成功返回0,否则返回错误编号

  18. /************************* 读写锁属性 ************************************/
  19. 27、int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
  20.     int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
  21.     返回值:成功返回0,否则返回错误编号

  22. 28、设置获取读写锁属性,线程间为:PTHREAD_PROCESS_PRIVATE,进程间为:PTHREAD_PROCESS_SHARED
  23.     int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *
  24.                   restrict attr, int *restrict pshared);
  25.     int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,
  26.           int pshared);
  27.     返回值:成功返回0,否则返回错误编号

  28. /************************* 条件变量属性 ************************************/
  29. 29、int pthread_condattr_destroy(pthread_condattr_t *attr);
  30.     int pthread_condattr_init(pthread_condattr_t *attr);
  31.     返回值:成功返回0,否则返回错误编号

  32. 30、设置获取条件变量属性,线程间为:PTHREAD_PROCESS_PRIVATE,进程间为:PTHREAD_PROCESS_SHARED
  33.     int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr,
  34.           int *restrict pshared);
  35.     int pthread_condattr_setpshared(pthread_condattr_t *attr,
  36.           int pshared);
  37.     返回值:成功返回0,否则返回错误编号
 
2、重入
替代函数:
阅读(1255) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~