http://www.cnblogs.com/skynet/archive/2010/10/30/1865267.html
pthread_exit($num) 指定返回值,其他线程通过pthread_join()来获得
return 直接返回
exit 退出进程
临界区,临界区内的代码不会被中断打扰,具有原子性质
https://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/
线程函数表
线程
创建 pthread_create()
退出 pthread_exit()
等待 pthread_join()
互斥锁
创建 pthread_mutex_init()
销毁 pthread_mutex_destroy()
加锁 pthread_mutex_lock()
解锁 pthread_mutex_unlock()
条件
创建 pthread_cond_init()
销毁 pthread_cond_destroy()
触发 pthread_cond_signal()
广播 pthread_cond_broadcast()
等待 pthread_cond_wait()/pthread_cond_timedwait()
尽量设置recursive属性初始化互斥锁
pthread_mutex_t *mutex = new pthread_mutex_t
pthread_mutexattr_t mutexattr //= new pthread_mutexattr
pthread_mutexattr_init(&mutexattr)
pthread_mutexattr_settype(&mutexattr, pthread_MUTEX_RECURSIVE_NP) //pthread_MUTEXATTR_RECURSIVE)
pthread_mutex_init(mutex, &mutexattr) //&mutex, mutexattr)
pthread_mutexattr_destroy(&mutexattr)
pthread_mutex_lock(mutex)
pthread_mutex_unlock(mutex)
pthread_exit($num) 指定返回值,其他线程通过pthread_join()来获得
return 直接返回
exit 退出进程
临界区,临界区内的代码不会被中断打扰,具有原子性质
https://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/
线程函数表
线程
创建 pthread_create()
退出 pthread_exit()
等待 pthread_join()
互斥锁
创建 pthread_mutex_init()
销毁 pthread_mutex_destroy()
加锁 pthread_mutex_lock()
解锁 pthread_mutex_unlock()
条件
创建 pthread_cond_init()
销毁 pthread_cond_destroy()
触发 pthread_cond_signal()
广播 pthread_cond_broadcast()
等待 pthread_cond_wait()/pthread_cond_timedwait()
尽量设置recursive属性初始化互斥锁
pthread_mutex_t *mutex = new pthread_mutex_t
pthread_mutexattr_t mutexattr //= new pthread_mutexattr
pthread_mutexattr_init(&mutexattr)
pthread_mutexattr_settype(&mutexattr, pthread_MUTEX_RECURSIVE_NP) //pthread_MUTEXATTR_RECURSIVE)
pthread_mutex_init(mutex, &mutexattr) //&mutex, mutexattr)
pthread_mutexattr_destroy(&mutexattr)
pthread_mutex_lock(mutex)
pthread_mutex_unlock(mutex)