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

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

commit 0f7c992cea40e63cd8475d73b3d85a228bcfbc82
Author: hujun5 <[email protected]>
AuthorDate: Fri Jun 6 18:32:01 2025 +0800

    sched/task: fix gettid by moving tls_dup_info after child pid initialization
    
    Move tls_dup_info() call to after child process priority is set, ensuring
    the child's pid is properly initialized before duplicating TLS information.
    This fixes incorrect thread ID assignment during task fork operations.
    
    Signed-off-by: hujun5 <[email protected]>
---
 sched/task/task_fork.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c
index 964c55b0395..359db312f48 100644
--- a/sched/task/task_fork.c
+++ b/sched/task/task_fork.c
@@ -221,14 +221,6 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr)
     }
 #endif
 
-  /* Setup thread local storage */
-
-  ret = tls_dup_info(child, parent);
-  if (ret < OK)
-    {
-      goto errout_with_tcb;
-    }
-
   /* Get the priority of the parent task */
 
 #ifdef CONFIG_PRIORITY_INHERITANCE
@@ -247,6 +239,14 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr)
       goto errout_with_tcb;
     }
 
+  /* Setup thread local storage */
+
+  ret = tls_dup_info(child, parent);
+  if (ret < OK)
+    {
+      goto errout_with_tcb;
+    }
+
   /* Setup to pass parameters to the new task */
 
   ret = nxtask_setup_stackargs(child, argv[0], &argv[1]);

Reply via email to