一、线程编程
1、基本编程
(1)函数说明
1) pthread_create():创建线程
2)pthread_exit():线程退出
3)pthread_join():将当前线程挂起并等待线程结束,线程结束时资源被收回
4)pthread_cancel():用于同一进程内一个线程要终止另一个线程,被终止的线程要调用以下两个函数
5)pthread_setcancel():设置线程是否可以被其他线程调用pthread_cancel函数取消/终止
6)pthread_setcanceltype():设置当前线程的“可取消类型”,并且将先前的类型返回到oldtype引用中
(2)函数格式
1)pthread_create()函数
a、头文件:#include <pthread.h>
b、函数原型:int pthread_create((pthread_t *thread,pthread_attr_t *attr,void *(*start_routine)),void *arg)
c、参数:
thread:线程标识符
attr:线程属性设置,通常取为NULL
start_routine:线程函数的起始地址,是一个以指向void的指针作为参数和返回值的函数指针
arg:传递给start_routine的参数
d、返回值:
成功:0
出错:返回错误码
2)pthread_exit()函数
a、头文件ÿ
拓展九之嵌入式多线程
最新推荐文章于 2024-05-04 08:57:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)