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_base_t stat ;
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+ stat = rt_sched_thread_get_stat (thread );
495+
496+ /* assert thread is not already closed to prevent duplicate deletion */
497+ RT_ASSERT (stat != RT_THREAD_CLOSE );
498+
499+ /* warn if deleting a running or ready thread */
500+ if ((stat == RT_THREAD_RUNNING ) || (stat == RT_THREAD_READY ))
501+ {
502+ rt_exit_critical_safe (critical_level );
503+ LOG_D ("deleting thread [%s] in %s may cause problems" ,
504+ thread -> parent .name ,
505+ (stat == 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