线程同步的方式:互斥锁,无名信号量,条件变量
互斥锁:初始化互斥锁:静态创建:pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
动态创建:int pthread_mutex_init(pthread_mutex_t * __restrict, const pthread_mutexattr_t *_Nullable __restrict);
上锁: int pthread_mutex_lock(pthread_mutex_t *);
解锁:int pthread_mutex_lock(pthread_mutex_t *)
销毁锁:int pthread_mutex_destory(pthread_mutex_t *)
条件变量:初始化条件变量:int pthread_cond_init(pthread_cond_t *restrict,const pthread_condattr_t * _Nullable __restrict)
当条件不满足:int pthread_cond_wait(pthread_cond_t * __restrict,pthread_mutex_t * __restrict)
满足条件:int pthread_cond_signal(pthread_cond_t *)
释放条件变量:int pthread_cond_destory(pthread_cond_t *)
信号量:初始化:int sem_init(sem_t *,int ,unsigned int)
当条件不满足时:阻塞:int sem_wait(sem_t *)
非阻塞:int sem_trywait(sem_t *)
唤醒:int sem_post(sem_t *)
释放:int sem_destory(sem_t *)