gustavonihei commented on PR #6322:
URL: https://github.com/apache/incubator-nuttx/pull/6322#issuecomment-1136361775

   The Wi-Fi library creates a new semaphore for every thread that performs 
connection operations, so we cannot have a global pointer.
   Since these semaphores are thread-local, this motivated the initial 
implementation based on `pthread_key_t`, so that the semaphores were being 
stored in Thread Local Storage, and then could be destroyed on thread 
termination. The solution here was based on the one implemented for ESP-IDF, 
which works as expected.
   
   But on NuttX it resulted in the semaphores not being destroyed. I'll try to 
explain why.
   The Wi-Fi library operates in a dedicated Kernel Thread, named `wifi`. But 
the `pthread_key_t` and the destructor for the semaphores were allocated to the 
Thread Local Storage of the `init` thread.
   Every network-related request from the application will be handled by the 
`wifi` kernel thread and its child pthreads. The issue is that those child 
pthreads do not belong to the same Task Group from the `init` thread, which is 
the one whose TLS area contains the semaphore destructor.
   
   So the catch here is that NuttX provides this process-like abstraction which 
segregates pthreads created from different tasks. So a pthread created from 
**Task B** won't be able to share keys with another pthread from **Task A**.


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to