diff --git a/sched/pthread/pthread_findjoininfo.c b/sched/pthread/pthread_findjoininfo.c index f977a33642..cf9101ef5e 100644 --- a/sched/pthread/pthread_findjoininfo.c +++ b/sched/pthread/pthread_findjoininfo.c @@ -140,7 +140,8 @@ FAR struct join_s *pthread_findjoininfo(FAR struct task_group_s *group, { FAR struct tcb_s *tcb = nxsched_get_tcb((pthread_t)pid); - if (tcb != NULL && (tcb->flags & TCB_FLAG_DETACHED) == 0) + if (tcb != NULL && (tcb->flags & TCB_FLAG_DETACHED) == 0 && + (tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { pjoin = pthread_createjoininfo((FAR struct pthread_tcb_s *)tcb); } diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index 398e35100d..b864b64e75 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -75,6 +75,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR struct join_s *pjoin; + FAR struct tcb_s *tcb; int ret; sinfo("thread=%d group=%p\n", thread, group); @@ -84,11 +85,18 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) enter_cancellation_point(); + tcb = nxsched_get_tcb(thread); + if (tcb != NULL && tcb->group != group) + { + leave_cancellation_point(); + return EINVAL; + } + /* First make sure that this is not an attempt to join to * ourself. */ - if ((pid_t)thread == gettid()) + if (tcb == rtcb) { leave_cancellation_point(); return EDEADLK; @@ -114,8 +122,6 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) { /* Determine what kind of error to return */ - FAR struct tcb_s *tcb = nxsched_get_tcb((pthread_t)thread); - swarn("WARNING: Could not find thread data\n"); /* Case (1) or (3) -- we can't tell which. Assume (3) */