File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -482,13 +482,30 @@ static rt_err_t _thread_detach(rt_thread_t thread)
482482{
483483 rt_err_t error ;
484484 rt_base_t critical_level ;
485+ rt_uint8_t thread_status ;
485486
486487 /**
487488 * forbid scheduling on current core before returning since current thread
488489 * may be detached from scheduler.
489490 */
490491 critical_level = rt_enter_critical ();
491492
493+ /* get thread status and warn about unsafe deletion scenarios */
494+ thread_status = rt_sched_thread_get_stat (thread );
495+
496+ /* assert thread is not already closed to prevent duplicate deletion */
497+ RT_ASSERT (thread_status != RT_THREAD_CLOSE );
498+
499+ /* warn if deleting a running or ready thread */
500+ if ((thread_status == RT_THREAD_RUNNING ) || (thread_status == RT_THREAD_READY ))
501+ {
502+ rt_exit_critical_safe (critical_level );
503+ LOG_W ("Warning: Deleting active thread [%s] in %s state may cause resource leak" ,
504+ thread -> parent .name ,
505+ (thread_status == RT_THREAD_RUNNING ) ? "RUNNING" : "READY" );
506+ critical_level = rt_enter_critical ();
507+ }
508+
492509 error = rt_thread_close (thread );
493510
494511 _thread_detach_from_mutex (thread );
You can’t perform that action at this time.
0 commit comments