Skip to content

Commit 65b7f43

Browse files
authored
Merge pull request #2329 from RT-Thread/fix_pthread
[ptherad] Fix pthread_exit issue
2 parents 509a6c1 + f9f7e6c commit 65b7f43

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

components/libc/pthreads/pthread.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ void pthread_exit(void *value)
346346
ptd->tls = RT_NULL;
347347
}
348348

349-
if (ptd->attr.detachstate == PTHREAD_CREATE_JOINABLE)
350-
{
351-
/* release the joinable pthread */
352-
rt_sem_release(ptd->joinable_sem);
353-
}
354-
355349
/* detach thread */
356350
rt_thread_detach(ptd->tid);
357351
/* reschedule thread */

src/thread.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,17 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
347347
/* change stat */
348348
thread->stat = RT_THREAD_CLOSE;
349349

350-
/* detach object */
351-
rt_object_detach((rt_object_t)thread);
352-
353-
if (thread->cleanup != RT_NULL)
350+
if ((rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) &&
351+
thread->cleanup == RT_NULL)
352+
{
353+
rt_object_detach((rt_object_t)thread);
354+
}
355+
else
354356
{
355357
/* disable interrupt */
356358
lock = rt_hw_interrupt_disable();
357-
358359
/* insert to defunct thread list */
359360
rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));
360-
361361
/* enable interrupt */
362362
rt_hw_interrupt_enable(lock);
363363
}
@@ -366,7 +366,6 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
366366
}
367367
RTM_EXPORT(rt_thread_detach);
368368

369-
370369
#ifdef RT_USING_HEAP
371370
/**
372371
* This function will create a thread object and allocate thread object memory

0 commit comments

Comments
 (0)