第26章 线程

时间:2022-05-03
本文章向大家介绍第26章 线程,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include <pthread.h>

//线程
int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void*), void *arg);
int pthread_join(pthread_t *tid, void **status);
pthread_t pthread_self(void);
int pthread_detach(pthread_t tid);
void pthread_exit(void *status);

//线程特定数据
int pthread_once(pthread_once_t *onceptr/*PTHREAD_ONCE_INIT*/, void (*init)(void));
int pthread_key_create(pthread_key_t *keyptr, void (*destructor)(void *value));
void *pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);

//互斥锁
int pthread_mutex_lock(pthread_mutex_t *mptr);
int pthread_mutex_unlock(pthread_mutex_t *mptr);

//条件变量
int pthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr);
int pthread_cond_signal(pthread_cond_t *cptr);
int pthread_cond_broadcast(pthread_cond_t *cptr);
int pthread_cond_timedwait(pthread_cond_t *cptr, pthread_mutex_t *mptr, const struct timespec *abstime);//gettimeofday clock_gettime