什么是线程同步?
线程同步指的是当一个线程在对某个临界资源进行操作时,其他线程都不可以对这个资源进行操作,直到该线程完成操作。
pthread_create()
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);//用于创建新的线程
//*thread,指向线程标识符的指针,用于存储新线程的标识符
//attr,通常位NULL
//start_routine,指向线程主函数的指针,新线程将从这个函数开始执行
pthread_join()
互斥锁
pthread_mutex_init()
pthread_mutex_lock()
pthread_mutex_unlock()
pthread_mutex_destroy()
实践
信号量
sem_init()
sem_wait()
sem_post()
sem_destroy()
实践
条件变量
pthread_cond_init()
pthread_cond_wait()
pthread_cond_signal()
pthread_cond_broadcast()
pthread_cond_destroy()
实践
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。