Browse Source

[kernel] sync with pthread_exit issue in master

Bernard Xiong 6 years ago
parent
commit
45f3cf7824
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/thread.c

+ 6 - 7
src/thread.c

@@ -326,17 +326,17 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
     /* change stat */
     thread->stat = RT_THREAD_CLOSE;
 
-    /* detach object */
-    rt_object_detach((rt_object_t)thread);
-
-    if (thread->cleanup != RT_NULL)
+    if ((rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) &&
+        thread->cleanup == RT_NULL)
+    {
+        rt_object_detach((rt_object_t)thread);
+    }
+    else
     {
         /* disable interrupt */
         lock = rt_hw_interrupt_disable();
-
         /* insert to defunct thread list */
         rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));
-
         /* enable interrupt */
         rt_hw_interrupt_enable(lock);
     }
@@ -345,7 +345,6 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
 }
 RTM_EXPORT(rt_thread_detach);
 
-
 #ifdef RT_USING_HEAP
 /**
  * This function will create a thread object and allocate thread object memory