You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/05/24 19:42:43 UTC

[GitHub] [incubator-nuttx] gustavonihei commented on pull request #6322: ESP32/ESP32-C3: Fix leak of semaphores created by Wi-Fi kernel thread

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-unsubscribe@nuttx.apache.org

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