- 创建线程
pthread_create
- 启动线程
pthread_join
- 线程锁
//互斥锁
pthread_mutex_t mutex;
//条件变量
pthread_cond_t has_product;
pthread_mutex_lock(&mutex);
...
pthread_cond_signal(&has_product);
pthread_cond_broadcast(&player->cond);
pthread_cond_timeout_np(&player->cond,&player->mutex, sleep_time/1000ll);
...
pthread_mutex_unlock(&mutex);
//销毁互斥锁和条件变量
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&has_product);
网友评论