#i nclude <pthread.h>
int pthread_equal(pthread_t tid1, pthread_t tid2)
|
#i nclude <pthread.h>
pthread _t pthread_self(void);
|
#i nclude <pthread.h>
int pthread_create(
pthread_t *restrict tidp,
const pthread_attr_t *restrict attr,
void *(*start_rtn)(void *), void *restrict arg);
|
#i nclude <pthread.h>
void pthread_exit(void *rval_ptr);
int pthread_join(pthread_t thread, void **rval_ptr);
|
#i nclude <pthread.h>
void pthread_cancel(pthread_t tid)
|
#i nclude <pthread.h>
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 <pthread.h>
int pthread_detach(pthread_t tid);
|
#i nclude <pthread.h>
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 <pthread.h>
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 <pthread.h>
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 <pthread.h>
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);
|
#i nclude <pthread.h>
int pthread_cond_init(
pthread_cond_t *restrict cond,
const pthread_condxattr_t *restrict attr)
int pthread_cond_destroy(pthread_cond_t *cond);
|
#i nclude <pthread.h>
int pthread_cond_wait(
pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex);
int pthread_cond_timedwait(
pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex,
const struct timespec *restrict timeout);
|
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
|
#i nclude <pthread.h>
int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_broadcast(pthread_cond_t *cond);
|