条件变量相关函数、虚假唤醒
初始化一个条件变量
#include <pthread.h>
int pthread_cond_init(pthread_cond_t *restrict cond,
const pthread_condattr_t *restrict attr);
常量初始化
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
摧毁一个条件变量
#include <pthread.h>
int pthread_cond_destroy(pthread_cond_t *cond);
条件变量阻塞等待
#include <pthread.h>
int pthread_cond_wait(pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex);
先释放锁 mutex
阻塞在 cond 条件变量上
超时等待
#include <pthread.h>
int pthread_cond_timedwait(pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex,
const struct timespec *restrict abstime);
struct timespec {
time_t tv_sec;