From 858af4295c9850e21b514ad5075967c84b8cb392 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 6 Sep 2016 07:34:09 -0600 Subject: [PATCH] The TCB nchildren field should not be incremented when pthreads are created. --- sched/sched/sched_waitid.c | 2 ++ sched/sched/sched_waitpid.c | 1 + sched/task/task_reparent.c | 2 ++ sched/task/task_setup.c | 13 +++++++++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 003f8b597f..7f7aa71747 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -239,6 +239,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) } } #else + /* Child status is not retained. */ + if (rtcb->nchildren == 0) { /* There are no children */ diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 0e3902342b..a8f164c039 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -383,6 +383,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb(pid); + #ifdef HAVE_GROUP_MEMBERS if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid) #else diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index 690294ec02..13cbbc39a2 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -190,6 +190,7 @@ int task_reparent(pid_t ppid, pid_t chpid) } #else /* CONFIG_SCHED_CHILD_STATUS */ + /* Child task exit status is not retained */ DEBUGASSERT(otcb->nchildren > 0); @@ -302,6 +303,7 @@ int task_reparent(pid_t ppid, pid_t chpid) } #else /* CONFIG_SCHED_CHILD_STATUS */ + /* Child task exit status is not retained */ DEBUGASSERT(otcb->nchildren > 0); diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 6d0ea9c2b2..7a2297a105 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -275,8 +275,17 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) } } #else - DEBUGASSERT(rtcb->nchildren < UINT16_MAX); - rtcb->nchildren++; + /* Child status is not retained. Simply keep track of the number + * child tasks (not pthreads) created. + */ + +#ifndef CONFIG_DISABLE_PTHREAD + if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) +#endif + { + DEBUGASSERT(rtcb->nchildren < UINT16_MAX); + rtcb->nchildren++; + } #endif } #else