sched/pthread: save pid before task activate

When a high-priority pthread is created,
ptcb may be released after nxtask_activate.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
This commit is contained in:
zhangyuan29
2024-10-10 13:38:58 +08:00
committed by Xiang Xiao
parent 2ed88f8813
commit 8acc3b4771
+4 -4
View File
@@ -442,12 +442,8 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
#endif
}
/* Then activate the task */
sched_lock();
nxtask_activate((FAR struct tcb_s *)ptcb);
/* Return the thread information to the caller */
if (thread != NULL)
@@ -455,6 +451,10 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
*thread = (pthread_t)ptcb->cmn.pid;
}
/* Then activate the task */
nxtask_activate((FAR struct tcb_s *)ptcb);
sched_unlock();
return OK;