Linux线程
文章平均质量分 53
puppet^K
这个作者很懒,什么都没留下…
展开
-
线程同步之互斥量加锁解锁
1.创建及销毁互斥锁 #include <pthread.h> int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); int pthread_mutex_destroy(pthread_mutex_t mutex); // 返回:若成功返回0,否则返回错误编号 要用默认的属性初始化互斥量,只需把attr设置为NULL。 2.加锁及解锁 #in原创 2021-09-23 14:38:30 · 204 阅读 · 0 评论 -
什么情况造成线程间死锁
原创 2021-09-23 14:28:57 · 39 阅读 · 0 评论 -
线程创建等待及退出
1.线程创建 #include <pthread.h> int pthread_create(pthread_t *restrict tidp, const pthread_attr_t *restrict attr, void *(*start_rtn)(void *), void *restrict arg); // 返回:若成功返回0,否则返回错误编号 当pthread_create成功返回时,由tidp指向的内存单元被设置为新创建线程的线程ID。attr参数用于定制各种不同的线程属原创 2021-09-23 14:24:33 · 285 阅读 · 0 评论 -
线程条件控制实现线程的同步
一.条件变量相关API 1.创建及销毁条件变量 #include <pthread.h> int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr); int pthread_cond_destroy(pthread_cond_t *restrict cond); // 返回:若成功返回0,否则返回错误编号 除非需要创建一个非默认属性的条件变量,否则pthrea原创 2021-09-23 13:52:19 · 41 阅读 · 0 评论