gcc filename
-lpthread
int pthread_create(pthread_t *tidp,const pthread_attr_t *attr,void *(*start_rtn)(void),void *arg)
tidp 线程id
attr 线程属性(通常为空)
start_rtn 线程要执行的函数
arg start_rtn 的参数
线程等待
int pthread_join(pthread_t tid,void **rval_ptr)
功能 阻塞调用线程,直到指定的线程终止
Tid 等待退出的线程id
Rval_ptr 线程退出的返回值的指针
线程标识
pthread_t pthread_self(void)
没有参数,返回值就为当前线程ID
清除 //先进后出
从pthread_cleanup_push的调用点到pthread_cleanup_pop
之间的程
序段中的终止运作(包括调用pthread_exit()和异常终止,
不包括return)
都将执行pthread_cleanup_push()所指定的清理函数。
void pthread_cleanup_push(void(*rtn)(void*),void*arg)
功能 将清除函数压入清除栈
Rtn 清除函数
Arg 清除函数的参数
void pthread_cleanup_pop(int execute)
功能 将清除函数弹出清除栈
参数 Execute执行到pthread_cleanup_pop()时是否在弹出
清理函数的同时执行该函数,非0:
执行;0:
不执行