进程/线程控制:
创建
退出
等待
多进程
fork()
exit() wait()
多线程 pthread_create pthread_exit() pthread_join()
线程的同步与互斥:
线程的互斥: 互斥锁
初始化互斥锁 int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);
注销互斥锁
int pthread_mutex_destroy(pthread_mutex_t *mutex);
加锁 int pthread_mutex_lock(pthread_mutex_t *mutex);
解锁 int pthread_mutex_unlock(pthread_mutex_t *mutex);
测试加锁
int pthread_mutex_trylock(pthread_mutex_t *mutex)
线程的同步: 条件变量
创建:int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr);
注销:int pthread_cond_destroy(pthread_cond_t *cond);
等待:int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
激活:pthread_cond_signal()激活一个等待该条件的线程,存在多个等待线程时按入队顺序激活其中一个
pthread_cond_broadcast()则激活所有等待线程