随笔分类 - Linux C-线程相关函数
摘要:sem_tsem_initsem_waitsem_trywaitsem_timedwaitsem_postsem_destroy 生产者消费者实例:
阅读全文
摘要:pthread_cond_tpthread_cond_initpthread_cond_destroypthread_cond_waitpthread_cond_timedwaitpthread_cond_signalpthread_cond_broadcast 生产者消费者模型: 运行结果: Pr
阅读全文
摘要:读共享,写独占 pthread_rwlock_tpthread_rwlock_initpthread_rwlock_destroypthread_rwlock_rdlockpthread_rwlock_wrlockpthread_rwlock_tryrdlockpthread_rwlock_tryw
阅读全文
摘要:互斥锁实例: #include <pthread.h>pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;int pthread_mutex_destroy(pthread_mutex_t *mutex);int pthread_mutex_init(
阅读全文
摘要:#include <pthread.h>int pthread_detach(pthread_t tid); pthread_t tid: 分离线程的tid返回值:成功返回0,失败返回错误号。 一般情况下,线程终止后,其终止状态一直保留到其它线程调用pthread_join获取它的状态为止。但是线程
阅读全文
摘要:获取调用线程tid #include <pthread.h>pthread_t pthread_self(void); 示例: 运行结果: main thread: pid 4959 tid 9791296 (0x956740)new thread: pid 4959 tid 1480448 (0x
阅读全文
摘要:一. pthread_create() #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
阅读全文