完善资料让更多小伙伴认识你,还能领取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; } } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
413 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
1762 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1135 浏览 0 评论
1604 浏览 0 评论
1418 浏览 0 评论
74678 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 16:46 , Processed in 0.595702 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号