Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,30 @@ static rt_err_t _thread_detach(rt_thread_t thread)
{
rt_err_t error;
rt_base_t critical_level;
rt_base_t stat;

/**
* forbid scheduling on current core before returning since current thread
* may be detached from scheduler.
*/
critical_level = rt_enter_critical();

/* get thread status and warn about unsafe deletion scenarios */
stat = rt_sched_thread_get_stat(thread);

/* assert thread is not already closed to prevent duplicate deletion */
RT_ASSERT(stat != RT_THREAD_CLOSE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面的 rt_thread_close 里面也检查了这个


/* warn if deleting a running or ready thread */
if ((stat == RT_THREAD_RUNNING) || (stat == RT_THREAD_READY))
{
rt_exit_critical_safe(critical_level);
LOG_D("deleting thread [%s] in %s may cause problems",
thread->parent.name,
(stat == RT_THREAD_RUNNING) ? "RUNNING" : "READY");
critical_level = rt_enter_critical();
}

error = rt_thread_close(thread);

_thread_detach_from_mutex(thread);
Expand Down