From 3ac9eece5a7b38ebdd90e8cd47a4e1d6fde5105d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 8 Jan 2022 16:30:22 -0500 Subject: [PATCH] =?UTF-8?q?[kernel]=20rt=5Fthread=5Fsuspend/resume?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/thread.c b/src/thread.c index d1cc848777..6c221c1f29 100644 --- a/src/thread.c +++ b/src/thread.c @@ -805,7 +805,11 @@ RTM_EXPORT(rt_thread_control); /** * @brief This function will suspend the specified thread and change it to suspend state. * - * @note This function only can suspend current thread itself. + * @note This function ONLY can suspend current thread itself. + * Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads. + * You have no way of knowing what code a thread is executing when you suspend it. + * If you suspend a thread while it is executing a critical area which is protected by a mutex, + * other threads attempt to use that mutex and have to wait. Deadlocks can occur very easily. * * @param thread is the thread to be suspended. * @@ -833,11 +837,6 @@ rt_err_t rt_thread_suspend(rt_thread_t thread) /* disable interrupt */ temp = rt_hw_interrupt_disable(); - if (stat == RT_THREAD_RUNNING) - { - /* not suspend running status thread on other core */ - RT_ASSERT(thread == rt_thread_self()); - } /* change thread stat */ rt_schedule_remove_thread(thread); @@ -857,6 +856,8 @@ RTM_EXPORT(rt_thread_suspend); /** * @brief This function will resume a thread and put it to system ready queue. * + * @note Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads. + * * @param thread is the thread to be resumed. * * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed. -- GitLab