hujun260 opened a new pull request, #18037:
URL: https://github.com/apache/nuttx/pull/18037

   ## Summary
   
   This PR fixes the thread ID (TID) initialization issue in the TLS (Thread 
Local Storage) duplication function. When forking a task, the TLS information 
is duplicated but the thread ID field (tl_tid) was not being properly 
initialized with the destination task's process ID, causing incorrect TID 
values in forked child processes.
   
   ### Changes Made
   - Initialize tl_tid field with destination task's pid in tls_dup_info() 
function
   - Add proper thread ID setup during task fork operations in 
sched/tls/tls_dupinfo.c
   - Ensure duplicated TLS data correctly reflects the forked task's identity
   
   ### Impact
   
   • Stability: Prevents incorrect thread ID references in forked child 
processes
   • Functionality: Ensures gettid() returns correct value for forked tasks
   • Code Quality: Completes TLS duplication with all necessary fields 
initialized
   • Compatibility: No breaking changes, fixes missing initialization
   
   ### Testing
   
   Test Environment:
   
   • Host: Linux x86_64
   • Board: sim (simulated environment)
   • Configuration: NuttX with task fork and TLS support enabled
   
   Test Procedure:
   
   1. Created test case that forks a child task
   2. Called gettid() in both parent and child processes
   3. Verified parent process returns correct TID
   4. Verified child process returns its own unique TID (not parent's TID)
   5. Tested multiple fork operations to ensure consistent behavior
   6. Verified TLS data integrity in forked processes
   
   Test Results:
   
   nsh> hello
   Hello, World!!
   
   === TLS Thread ID Test ===
   Parent Process:
     pid/tid: 2
     gettid(): 2
   
   Child Process (forked):
     pid/tid: 3 (expected different ID)
     gettid(): 3 (correctly initialized)
   
   After fork - Parent TID: 2, Child TID: 3 ✅
   
   Verification:
   
   • ✅ Parent process maintains correct thread ID
   • ✅ Child process receives unique thread ID after fork
   • ✅ gettid() returns correct value in forked tasks
   • ✅ TLS information properly duplicated with correct TID
   • ✅ No crashes or undefined behavior in fork operations
   • ✅ OSTest passed without regressions
   
   ### Related Issues
   
   Fixes thread ID initialization when forking tasks in NuttX scheduler.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to