This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d4646190e3 sched/pthread: Stop sporadic scheduling when creation 
fails.
8d4646190e3 is described below

commit 8d4646190e3468f999113911e11f7d9d087d91e9
Author: yushuailong <[email protected]>
AuthorDate: Sun Oct 18 16:31:17 2026 +0800

    sched/pthread: Stop sporadic scheduling when creation fails.
    
    Sporadic scheduling can be initialized before scheduler setup or TLS
    initialization fails in nx_pthread_create().  The error path releases
    the TCB without canceling its replenishment watchdogs or freeing the
    sporadic state.
    
    Stop initialized sporadic scheduling in a critical section before
    releasing the TCB.  Check the state pointer because failures can also
    occur before sporadic scheduling is initialized.  Builds without
    CONFIG_SCHED_SPORADIC are unchanged.
    
    Assisted-by: Codex:GPT-6
    Signed-off-by: yushuailong <[email protected]>
---
 sched/pthread/pthread_create.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c
index c06d3c104a2..ce38c32a3d0 100644
--- a/sched/pthread/pthread_create.c
+++ b/sched/pthread/pthread_create.c
@@ -485,6 +485,21 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR 
pthread_t *thread,
 
 errout_with_tcb:
 
+#ifdef CONFIG_SCHED_SPORADIC
+  /* Stop sporadic scheduling before releasing the TCB referenced by its
+   * replenishment timers.
+   */
+
+  if (ptcb->sporadic != NULL)
+    {
+      irqstate_t flags = enter_critical_section();
+
+      DEBUGVERIFY(nxsched_stop_sporadic(ptcb));
+
+      leave_critical_section(flags);
+    }
+#endif
+
   /* Since we do not join the group, assign group to NULL to clear binding */
 
   ptcb->group = NULL;

Reply via email to