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

   ## Summary
   
   `exit()` and `quick_exit()` ran the destructors of the thread-specific data 
before the functions registered with `atexit()` and `at_quick_exit()`. An exit 
function that used thread-specific data, or a `__thread` variable (emulated TLS 
keeps it there), then saw the data of a new thread: for example, a program that 
recorded a held lock in a `__thread` flag locked it again from its exit 
function and failed with `EDEADLK`.
   
   This PR calls the exit functions first, while the data of the thread is 
still valid. Then `exit()` runs the TLS destructors and closes what `dlopen()` 
left open, as before.
   
   ## Impact
   
   Exit functions see the thread-specific data and the `__thread` variables of 
the calling thread. Nothing else changes.
   
   ## Testing
   
   A test program on `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4, 
`CONFIG_TLS_NELEM=4`). `main()` sets a `pthread_key_create()` key with a 
destructor and a `__thread` variable, registers an `atexit()` function and 
returns; the exit function checks the data:
   
   | Check in the exit function | master | this PR |
   |---|---|---|
   | The destructor of the key has not run yet | FAIL | PASS |
   | `pthread_getspecific()` gives the value | FAIL | PASS |
   | The `__thread` variable keeps its value | PASS | PASS |
   
   `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: 
Exiting with status 0`. `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
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