一.头文件

#include <pthread.h>

二.编译选项

-lpthread

三.结构体

pthread_t
pthread_attr_t
pthread_barrier_t
pthread_barrierattr_t
pthread_cond_t
pthread_condattr_t
pthread_key_t
pthread_mutex_t
pthread_mutexattr_t
pthread_once_t
pthread_rwlock_t
pthread_rwlockattr_t
pthread_spinlock_t

四.API函数

pthread_create() - thread creation //创建线程int pthread_create(pthread_t *restrict thread,const pthread_attr_t *restrict attr,void *(*start_routine)(void*), void *restrict arg);
pthread_detach() - detach a thread //解绑线程(子线程退出可以回收资源)int pthread_detach(pthread_t thread);
pthread_join() - wait for thread termination    //等待子进程结束 int pthread_join(pthread_t thread, void **value_ptr);
pthread_exit() - thread termination //线程退出 void pthread_exit(void *value_ptr);
pthread_self() - get calling thread's ID //获取线程自身idpthread_t pthread_self(void);
pthread_kill() - send a signal to a thread //发送结束信号给线程int pthread_kill(pthread_t thread, int sig);
pthread_equal() - compare thread IDs //比较线程idint pthread_equal(pthread_t t1, pthread_t t2);
pthread_cancel() - cancel execution of a thread //取消线程 int pthread_cancel(pthread_t thread);
pthread_cleanup_pop(), pthread_cleanup_push - establish cancelation handlers void pthread_cleanup_pop(int execute);void pthread_cleanup_push(void (*routine)(void*), void *arg);pthread_getcpuclockid() - access a thread CPU-time clock (ADVANCED REALTIME THREADS)int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id);
pthread_once() - dynamic package initialization int pthread_once(pthread_once_t *once_control,void (*init_routine)(void));
pthread_atfork() - register fork handlers int pthread_atfork(void (*prepare)(void), void (*parent)(void),void (*child)(void));
pthread_getconcurrency() - get level of concurrency int pthread_getconcurrency(void);
pthread_setconcurrency() - set level of concurrency int pthread_setconcurrency(int new_level);
pthread_getschedparam() - dynamic thread scheduling parameters access (REALTIME THREADS) int pthread_getschedparam(pthread_t thread, int *restrict policy,struct sched_param *restrict param);
pthread_setschedparam() - dynamic thread scheduling parameters access (REALTIME THREADS) int pthread_setschedparam(pthread_t thread, int policy,const struct sched_param *param);
pthread_getspecific() - thread-specific data management void *pthread_getspecific(pthread_key_t key);
pthread_setspecific() - thread-specific data management int pthread_setspecific(pthread_key_t key, const void *value);
pthread_key_create() - thread-specific data key creation int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
pthread_key_delete() - thread-specific data key deletion int pthread_key_delete(pthread_key_t key);
pthread_setcancelstate() - set cancelability state int pthread_setcancelstate(int state, int *oldstate);
pthread_setcanceltype() - set cancelability state int pthread_setcanceltype(int type, int *oldtype);
pthread_testcancel() - set cancelability state void pthread_testcancel(void);
pthread_setschedprio() - dynamic thread scheduling parameters access (REALTIME THREADS) int pthread_setschedprio(pthread_t thread, int prio);
pthread_sigmask() - examine and change blocked signals int pthread_sigmask(int how, const sigset_t *restrict set,sigset_t *restrict oset);
sigprocmask() - examine and change blocked signals int sigprocmask(int how, const sigset_t *restrict set,sigset_t *restrict oset);pthread_attr_init() - initialize threads attributes object int pthread_attr_init(pthread_attr_t *attr);
pthread_attr_destroy() - destroy threads attributes object int pthread_attr_destroy(pthread_attr_t *attr);
pthread_attr_getinheritsched() - get inheritsched attribute (REALTIME THREADS) int pthread_attr_getinheritsched(const pthread_attr_t *restrict attr,int *restrict inheritsched);
pthread_attr_setinheritsched() - set inheritsched attribute (REALTIME THREADS) int pthread_attr_setinheritsched(pthread_attr_t *attr,int inheritsched);
pthread_attr_getschedparam() - get schedparam attribute int pthread_attr_getschedparam(const pthread_attr_t *restrict attr,struct sched_param *restrict param);
pthread_attr_setschedparam() - set schedparam attribute int pthread_attr_setschedparam(pthread_attr_t *restrict attr,const struct sched_param *restrict param);
pthread_attr_getschedpolicy() - get schedpolicy attribute (REALTIME THREADS) int pthread_attr_getschedpolicy(const pthread_attr_t *restrict attr,int *restrict policy);
pthread_attr_setschedpolicy() - set schedpolicy attribute (REALTIME THREADS)int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
pthread_attr_getscope() - get contentionscope attribute (REALTIME THREADS) int pthread_attr_getscope(const pthread_attr_t *restrict attr,int *restrict contentionscope);
pthread_attr_setscope() - set contentionscope attribute (REALTIME THREADS) int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
pthread_attr_getstackaddr() - get stackaddr attribute int pthread_attr_getstackaddr(const pthread_attr_t *restrict attr,void **restrict stackaddr);
pthread_attr_setstackaddr() - set stackaddr attributeint pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
pthread_attr_getstack() - set stack attributes int pthread_attr_getstack(const pthread_attr_t *restrict attr,void **restrict stackaddr, size_t *restrict stacksize);
pthread_attr_setstack() - set stack attribute int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,size_t stacksize);
pthread_attr_getdetachstate() - get detachstate attribute int pthread_attr_getdetachstate(const pthread_attr_t *attr,int *detachstate);
pthread_attr_setdetachstate() - set detachstate attribute int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
pthread_attr_getguardsize() - get thread guardsize attribute int pthread_attr_getguardsize(const pthread_attr_t *restrict attr,size_t *restrict guardsize);
pthread_attr_setguardsize() - set thread guardsize attributeint pthread_attr_setguardsize(pthread_attr_t *attr,size_t guardsize);
pthread_attr_setstacksize() - set stacksize attribute int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
pthread_attr_getstacksize() - get stacksize attributeint pthread_attr_getstacksize(const pthread_attr_t *restrict attr,size_t *restrict stacksize);pthread_barrier_init() - initialize a barrier object (ADVANCED REALTIME THREADS) int pthread_barrier_init(pthread_barrier_t *restrict barrier,const pthread_barrierattr_t *restrict attr, unsigned count);
pthread_barrier_destroy() - destroy a barrier object (ADVANCED REALTIME THREADS) int pthread_barrier_destroy(pthread_barrier_t *barrier);
pthread_barrier_wait() - synchronize at a barrier (ADVANCED REALTIME THREADS) int pthread_barrier_wait(pthread_barrier_t *barrier);
pthread_barrierattr_init() - initialize barrier attributes object (ADVANCED REALTIME THREADS) int pthread_barrierattr_init(pthread_barrierattr_t *attr);
pthread_barrierattr_destroy() - destroy barrier attributes object (ADVANCED REALTIME THREADS) int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
pthread_barrierattr_getpshared(), pthread_barrierattr_setpshared - get and set process-shared attribute of barrier attributes object (ADVANCED REALTIME THREADS) int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict attr, int *restrict pshared);
pthread_barrierattr_setpshared() - set process-shared attribute of barrier attributes object (ADVANCED REALTIME THREADS) int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr,int pshared);pthread_condattr_init() - initialize condition variable attributes object int pthread_condattr_init(pthread_condattr_t *attr);
pthread_condattr_destroy() - destroy condition variable attributes object int pthread_condattr_destroy(pthread_condattr_t *attr);
pthread_condattr_getclock() - get the clock selection condition variable attribute (ADVANCED REALTIME) int pthread_condattr_getclock(const pthread_condattr_t *restrict attr,clockid_t *restrict clock_id);
pthread_condattr_setclock() - set the clock selection condition variable attribute int pthread_condattr_setclock(pthread_condattr_t *attr,clockid_t clock_id);
pthread_condattr_getpshared() - get the process-shared condition variable attributes int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr,int *restrict pshared);
pthread_condattr_setpshared() - set the process-shared condition variable attributesint pthread_condattr_setpshared(pthread_condattr_t *attr,int pshared);
pthread_cond_init() - initialize condition variables int pthread_cond_init(pthread_cond_t *restrict cond,const pthread_condattr_t *restrict attr);
pthread_cond_destroy() - destroy condition variables int pthread_cond_destroy(pthread_cond_t *cond);
pthread_cond_broadcast() - broadcast a condition int pthread_cond_broadcast(pthread_cond_t *cond);
pthread_cond_signal() - signal a condition int pthread_cond_signal(pthread_cond_t *cond);
pthread_cond_timedwait() - wait on a condition int pthread_cond_timedwait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex,const struct timespec *restrict abstime);
pthread_cond_wait() - wait on a condition int pthread_cond_wait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex); pthread_mutexattr_init() - initialize mutex attributes object int pthread_mutexattr_init(pthread_mutexattr_t *attr);
pthread_mutexattr_destroy() - destroy mutex attributes object int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
pthread_mutexattr_getprioceiling() - get prioceiling attribute of mutex attributes object (REALTIME THREADS)int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *restrict attr, int *restrict prioceiling);
pthread_mutexattr_setprioceiling() - set prioceiling attribute of mutex attributes object (REALTIME THREADS) int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,int prioceiling);
pthread_mutexattr_getprotocol() - get and set protocol attribute of mutex attributes object (REALTIME THREADS) int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict attr, int *restrict protocol);
pthread_mutexattr_setprotocol() - set protocol attribute of mutex attributes object (REALTIME THREADS) int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,int protocol);
pthread_mutexattr_getpshared() - get process-shared attribute int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict attr, int *restrict pshared);
pthread_mutexattr_setpshared() - set process-shared attribute int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,int pshared);
pthread_mutexattr_gettype() - get a mutex type attribute int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,int *restrict type);
pthread_mutexattr_settype() - set a mutex type attribute int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
pthread_mutex_init() - initialize a mutex int pthread_mutex_init(pthread_mutex_t *restrict mutex,const pthread_mutexattr_t *restrict attr);
pthread_mutex_destroy() - destroy a mutex int pthread_mutex_destroy(pthread_mutex_t *mutex);
pthread_mutex_getprioceiling() - get the priority ceiling of a mutex (REALTIME THREADS) int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict mutex,int *restrict prioceiling);
pthread_mutex_setprioceiling() - change the priority ceiling of a mutex (REALTIME THREADS) int pthread_mutex_setprioceiling(pthread_mutex_t *restrict mutex,int prioceiling, int *restrict old_ceiling);
pthread_mutex_lock() - lock a mutex int pthread_mutex_lock(pthread_mutex_t *mutex);
pthread_mutex_trylock() - lock a mutex int pthread_mutex_trylock(pthread_mutex_t *mutex);
pthread_mutex_timedlock() - lock a mutex (ADVANCED REALTIME) int pthread_mutex_timedlock(pthread_mutex_t *restrict mutex,const struct timespec *restrict abs_timeout);
pthread_mutex_unlock() - unlock a mutex int pthread_mutex_unlock(pthread_mutex_t *mutex);pthread_rwlockattr_init() - initialize read-write lock attributes object int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
pthread_rwlockattr_destroy() - destroy read-write lock attributes object int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
pthread_rwlockattr_getpshared() - get process-shared attribute of read-write lock attributes object int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict attr, int *restrict pshared);
pthread_rwlockattr_setpshared() - set process-shared attribute of read-write lock attributes object int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,int pshared);
pthread_rwlock_init() - initialize a read-write lock objectint pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,const pthread_rwlockattr_t *restrict attr);
pthread_rwlock_destroy() - destroy a read-write lock object int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
pthread_rwlock_rdlock() - lock a read-write lock object for readingint pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
pthread_rwlock_wrlock() - lock a read-write lock object for writing int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
pthread_rwlock_tryrdlock() - lock a read-write lock object for reading int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
pthread_rwlock_trywrlock() - lock a read-write lock object for writing int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
pthread_rwlock_timedrdlock() - lock a read-write lock for reading int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rwlock,const struct timespec *restrict abs_timeout);
pthread_rwlock_timedwrlock() - lock a read-write lock for writing int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rwlock,const struct timespec *restrict abs_timeout);
pthread_rwlock_unlock() - unlock a read-write lock object int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);pthread_spin_init() - initialize a spin lock object (ADVANCED REALTIME THREADS) int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
pthread_spin_destroy() - destroy a spin lock object (ADVANCED REALTIME THREADS) int pthread_spin_destroy(pthread_spinlock_t *lock);
pthread_spin_lock() - lock a spin lock object (ADVANCED REALTIME THREADS) int pthread_spin_lock(pthread_spinlock_t *lock);
pthread_spin_trylock() - lock a spin lock object (ADVANCED REALTIME THREADS) int pthread_spin_trylock(pthread_spinlock_t *lock);
pthread_spin_unlock() - unlock a spin lock object (ADVANCED REALTIME THREADS) int pthread_spin_unlock(pthread_spinlock_t *lock);

转载于:https://www.cnblogs.com/hehehaha/archive/2013/05/09/6332830.html

posix多线程有感--API相关推荐

  1. posix多线程有感--线程高级编程(线程和fork,exec)

    当多线程进程调用fork创建子进程时,Pthreads指定只有那个调用fork的线程在子进程内存在(表示子进程中只有调用线程这个线程).尽管当从fork调用返回时,只有调用线程在子进程中存在,所有其他 ...

  2. posix多线程有感--线程高级编程(条件变量)

    1.初始化条件变量pthread_cond_init int pthread_cond_init(pthread_cond_t *cv,const pthread_condattr_t *cattr) ...

  3. Singleton、MultiThread、Lib——实现单实例无锁多线程安全API

        前阵子写静态lib导出单实例多线程安全API时,出现了CRITICAL_SECTION初始化太晚的问题,之后查看了错误的资料,引导向了错误的理解,以至于今天凌晨看到另一份代码,也不多想的以为s ...

  4. 《POSIX多线程程序设计》读书笔记

    <POSIX多线程程序设计>读书笔记 一.      概述 1.    一个UNIX进程可以理解为一个线程加上地址空间.文件描述符和其他数据: 2.    多个线程可以共享一个地址空间,而 ...

  5. Linux Qt使用POSIX多线程条件变量、互斥锁(量)

    今天团建,但是文章也要写.酒要喝好,文要写美,方为我辈程序员的全才之路.嘎嘎 之前一直在看POSIX的多线程编程,上个周末结合自己的理解,写了一个基于Qt的用条件变量同步线程的例子.故此来和大家一起分 ...

  6. POSIX多线程程序设计_流水线工作例程

    #include<pthread.h> #include "errors.h"typedef struct stage_tag{<span style=" ...

  7. linux posix 线程池_posix多线程有感--自旋锁

    转自:http://www.csdn123.com/html/blogs/20130509/11141.htm 自旋锁是SMP架构中的一种low-level的同步机制. 当线程A想要获取一把自旋锁而该 ...

  8. POSIX多线程API函数

    创建 int pthread_create(pthread_t* tidp,const pthread_attr_t* attr,void* (*start_rtn)(void*), void* ar ...

  9. Delphi 多线程 (API篇)

    之前也接触过一些关于多线程的技术文章,但却总是很模糊的状态的,最近通过一个Demo 来一步步理解多线程以及线程同步技术.这篇文章主要是使用Delphi 提供的API 函数来创建线程,今后有时间写一下D ...

最新文章

  1. 关于html文档,关于HTML的简介
  2. 1分钟深入了解CSS3的动画属性animation
  3. multi-thread handling for batch request
  4. 你必须要懂的APK瘦身知识
  5. 简明 Python 教程学习笔记_2_函数
  6. MyEclipse 7.0 用java代码生成序列号
  7. 电商基础(一):跳出率和退出率
  8. 滴滴这车值不值得上?前Google全球技术总监郄小虎说来来来
  9. “并行程序VS串行程序”——并行程序优化实录
  10. android源码已关联设备,获取android设备已安装应用信息
  11. 强烈推荐一个有情怀的跨平台Redis可视化客户端工具:RedisViewer
  12. 迁移oracle数据库,简简单单的Oracle数据库迁移方法
  13. L2 Spare the spider 不要伤害蜘蛛
  14. 华为路由器 基本ACL配置
  15. java 传感器_JAVA串口采集传感器数据
  16. Facade(外观模式) 结构型
  17. 数据结构基本代码汇总
  18. node+express+mongodb初体验
  19. 拜占庭将军问题(二)——口头协议
  20. 3836mysql数据库应用基础教程答案_mysql intersect

热门文章

  1. go 判断元素是否在slice_Go内置数据结构原理
  2. 服务器tcp连接占满_漫画 | 一台Linux服务器最多能支撑多少个TCP连接?
  3. 选择将正确答案的序号填在括号里_小学四年级数学第五单元训练题,答案非常详细,见过的都保存了...
  4. 类继承(c++细节篇六)
  5. mysql修改root用户的密码
  6. CentOS7中Docker的安装与配置
  7. AndroidStudio中提示:This project uses AndroidX dependencies, but the ‘android.useAndroidX‘ property is
  8. Windows服务器上怎样开放指定端口
  9. Express中错误处理中间件的使用
  10. SpringBoot项目新建之后修改编译版本