MENU

标签 线程 下的文章

Linux多线程:线程与信号

每个线程都有自己的信号屏蔽字,新的线程会继承创建它的线程的信号屏蔽字。但是信号处理程序是所有线程共享的,也就是说一个线程注册了一个信号处理程序,其他线程就得使用这个信号处理程序。

阅读全文

Linux线程同步:条件变量(pthread_cond_t)

什么是条件变量

先看一下APUE第三版对于条件变量的说明:

Condition variables are another synchronization mechanism available to threads. These synchronization objects provide a place for threads to rendezvous. When used with mutexes, condition variables allow threads to wait in a race-free way for arbitrary conditions to occur.
The condition itself is protected by a mutex. A thread must first lock the mutex to change the condition state. Other threads will not notice the change until they acquire the mutex, because the mutex must be locked to be able to evaluate the condition.


阅读全文

使用pthread_create()创建线程

可以通过 pthread_create()函数创建新线程。

#include <pthread.h>
int pthread_create(pthread_t *restrict tidp,
                              const pthread_attr_t *restrict attr,
                              void *(*start_rtn)(void *),
                              void *restrict arg);

阅读全文