From 13d9383679a5d902c52e8d592d510ee8552ade70 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Wed, 1 Jul 2015 06:24:34 -0600 Subject: [PATCH] Group binding needs to be cleared before sched_releasetcb(), as otherwise group_leave() will be called and group->tg_nmembers decremented or group being released. group_leave() should be called only after group_join() is called, not after group_bind(). From Jussi Kivilinna. --- sched/pthread/pthread_create.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 8cfab5908fa..70fb9025919 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_create.c * - * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -241,6 +241,9 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, int errcode; pid_t pid; int ret; +#ifdef HAVE_TASK_GROUP + bool group_joined = false; +#endif /* If attributes were not supplied, use the default attributes */ @@ -368,6 +371,8 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, errcode = ENOMEM; goto errout_with_join; } + + group_joined = true; #endif /* Attach the join info to the TCB. */ @@ -451,6 +456,15 @@ errout_with_join: ptcb->joininfo = NULL; errout_with_tcb: +#ifdef HAVE_TASK_GROUP + /* Clear group binding */ + + if (ptcb && !group_joined) + { + ptcb->cmn.group = NULL; + } +#endif + sched_releasetcb((FAR struct tcb_s *)ptcb, TCB_FLAG_TTYPE_PTHREAD); return errcode; }