完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
线程循环结束后立即调用rt_thread_exit,后由空闲任务释放资源,但是线程句柄指针是不为空的,怎么能更好的判断这个线程资源被释放了呢。 rt_err_t Thread::join(int32_t millisec)
} |
|
相关推荐
1个回答
|
|
问题应该算是解决了,因为线程退出时候 会设置为CLOSE , join 的时候 在指针释放前调用 rt_thread_idle_excute ,释放内存 这样就能确保没问题了
/* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes */ #include "Thread.h" using namespace rtthread; Thread::Thread(rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick, const char *name) : _entry(RT_NULL), _param(RT_NULL), started(false),_stack_size(stack_size),_priority(priority),_tick(tick),_name(name) { rt_event_init(&_event, name, 0); _thread = rt_thread_create(name, (thread_func_t)func, this, stack_size, priority, tick); } Thread::Thread(void (*entry)(void *p), void *p, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick, const char *name) : _entry(entry), _param(p), started(false) { rt_event_init(&_event, name, 0); _thread = rt_thread_create(name, (thread_func_t)func, this, stack_size, priority, tick); } Thread::~Thread() { rt_event_detach(&_event); rt_thread_delete(_thread); } bool Thread::start() { /* if thread stop then create a new one */ if(join(0) == RT_EOK) { _thread = rt_thread_create(_name, (thread_func_t)func, this, _stack_size, _priority, _tick); } /* if thread is stop then start */ if(started == false) { if(rt_thread_startup(_thread) == RT_EOK) { started = true; } } return started; } void Thread::sleep(int32_t millisec) { rt_int32_t tick; if (millisec < 0) tick = 1; else tick = rt_tick_from_millisecond(millisec); rt_thread_delay(tick); } void Thread::func(Thread *pThis) { if (pThis->_entry != RT_NULL) { pThis->_entry(pThis->_param); } else { pThis->run(pThis->_param); } /* thread end event send*/ rt_event_send(&pThis->_event, 1); } void Thread::run(void *parameter) { /* please overload this method */ } rt_err_t Thread::wait(int32_t millisec) { return join(millisec); } rt_err_t Thread::join(int32_t millisec) { if (started) { rt_int32_t tick; if (millisec < 0) tick = -1; else tick = rt_tick_from_millisecond(millisec); rt_err_t ret = rt_event_recv(&_event, 1, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, tick, RT_NULL); /* if thread is end */ if(ret == RT_EOK) { /*run the idle excute to clean defunct thread*/ rt_thread_idle_excute(); /*set the thread handle null for next using*/ _thread = RT_NULL; started = false; } return ret; } else { return -RT_ENOSYS; } } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
754 浏览 0 评论
3703 浏览 0 评论
如何使用python调起UDE STK5.2进行下载自动化下载呢?
2459 浏览 0 评论
开启全新AI时代 智能嵌入式系统快速发展——“第六届国产嵌入式操作系统技术与产业发展论坛”圆满结束
2892 浏览 0 评论
获奖公布!2024 RT-Thread全球巡回线下培训火热来袭!报名提问有奖!
31079 浏览 11 评论
72788 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 21:38 , Processed in 0.396904 second(s), Total 41, Slave 35 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号