1.介绍
pthread_detach
函数用于设置一个线程的状态为分离(detached)。一旦线程被设置为分离状态,它在终止时会自动释放其资源,而不需要其他线程通过调用pthread_join
来回收。
int pthread_detach(pthread_t thread);
参数thread
是需要被设置为分离状态的线程的标识符。pthread_detach
函数成功时返回0,失败时返回一个错误码。
2.例子
#include <pthread.h>
#include <stdio.h>
void* thread_func(void* arg) {
printf("Hello from the detached thread!\n");
return NULL;
}
int main() {
pthread_t thread;
// 创建线程
if(pthread_create(&thread, NULL, thread_func, NULL)) {
fprintf(stderr, "Error creating thread\n");
return 1;
}
// 将线程设置为分离状态
if(pthread_detach(thread)) {
fprintf(stderr, "Error detaching thread\n");
return 2;
}
## 最后
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。**
**因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
![img](https://img-blog.csdnimg.cn/img_convert/1c972d322461f1ff05848cc60a35d34a.png)
![img](https://img-blog.csdnimg.cn/img_convert/6af719ea93ccd67d0af6c6aeefccc756.jpeg)
![img](https://img-blog.csdnimg.cn/img_convert/5b0898d0a4d45e36403a10b143550ea7.png)
![img](https://img-blog.csdnimg.cn/img_convert/44c1fc340dee6c9268f43d21e424417a.png)
![img](https://img-blog.csdnimg.cn/img_convert/83fa927445300091d6fc45fe78a0601c.png)
![img](https://img-blog.csdnimg.cn/img_convert/109234f8e22268db8da993a21c887b39.png)
![](https://img-blog.csdnimg.cn/img_convert/c84be51ff9b140e7ef1420a8cc4bd305.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618654289)
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**!!
文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**!!