全部博文(842)
分类: LINUX
2012-05-14 23:18:18
1 Introduction
#i nclude
int pthread_equal(pthread_t tid1, pthread_t tid2)
|
#i nclude
pthread _t pthread_self(void);
|
#i nclude
int pthread_create(
pthread_t *restrict tidp,
const pthread_attr_t *restrict attr,
void *(*start_rtn)(void *), void *restrict arg);
|
#i nclude
void pthread_exit(void *rval_ptr);
int pthread_join(pthread_t thread, void **rval_ptr
|
#i nclude
void pthread_cancel(pthread_t tid)
|
#i nclude
void pthread_cleanup_push(void (*rtn)(void *), void *arg);
void pthread_cleanup_pop(int execute);
|
void *thread_func(void *arg)
{
pthread_cleanup_push(cleanup, “handler”)
// do something
Pthread_cleanup_pop(0);
return((void *)0);
}
|
Process Primitive
|
Thread Primitive
|
Description
|
fork
|
pthread_create
|
创建新的控制流
|
exit
|
pthread_exit
|
退出已有的控制流
|
waitpid
|
pthread_join
|
等待控制流并获得结束代码
|
atexit
|
pthread_cleanup_push
|
注册在控制流退出时候被调用的函数
|
getpid
|
pthread_self
|
获得控制流的id
|
abort
|
pthread_cancel
|
请求非正常退出 |
#i nclude
int pthread_detach(pthread_t tid);
|
#i nclude
int pthread_mutex_init(
pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr)
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
#i nclude
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
#i nclude
int pthread_rwlock_init(
pthread_rwlock_t *restrict rwlock,
const pthread_rwlockattr_t *restrict attr)
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
|
#i nclude
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
|