From f9f7e6c5206c4b6573c33c4a233c1fbde2363389 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 14 Feb 2019 13:45:25 +0800 Subject: [PATCH] [ptherad] Fix pthread_exit issue When pthread invokes pthread_exit, it just detach self. --- components/libc/pthreads/pthread.c | 6 ------ src/thread.c | 13 ++++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c index 8e79aceb2a..55f46c0caa 100644 --- a/components/libc/pthreads/pthread.c +++ b/components/libc/pthreads/pthread.c @@ -346,12 +346,6 @@ void pthread_exit(void *value) ptd->tls = RT_NULL; } - if (ptd->attr.detachstate == PTHREAD_CREATE_JOINABLE) - { - /* release the joinable pthread */ - rt_sem_release(ptd->joinable_sem); - } - /* detach thread */ rt_thread_detach(ptd->tid); /* reschedule thread */ diff --git a/src/thread.c b/src/thread.c index b23d2fb6b9..0f2e1dc3d0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -347,17 +347,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); } @@ -366,7 +366,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 -- GitLab