线程的创建,回收,取消

  • 线程创建

 int pthread_create(pthread_t *th, const pthread_attr_t *attr,void *(*start_routine) (void *), void *arg);

   参数一:输出型参数,相当于线程号,指向线程标识符的指针

   参数二:用来设置线程属性

   参数三:输入型参数,线程运行函数的地址

   参数四:运行函数的参数

  • 线程回收

  1.  int pthread_join(pthread_t th, void **retval);

   参数一:线程标识符

   参数二:

 线程分离:脱离主线程,具体用法参考多线程网络聊天室那篇

   2.  int pthread_detach(pthread_t th);

  • 线程取消

  int pthread_cancel(pthread_t th);   //取消线程必须有相应的权限

  int pthread_setcancelstate(int state, int *oldstate);  //设置线程属性,具体属性参考man手册

  int pthread_setcanceltype(int type, int *oldtype);     //设置直接取消还是适当条件取消

  • 线程退出

 

你可能感兴趣的:(Linux应用编程网络编程笔记)