hujun260 commented on code in PR #18136:
URL: https://github.com/apache/nuttx/pull/18136#discussion_r2726576135


##########
libs/libc/pthread/pthread_mutex.c:
##########
@@ -56,18 +56,21 @@
  *
  ****************************************************************************/
 
-static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
+static inline_function
+void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
 {
-  FAR struct tls_info_s *tls = tls_get_info();
+  FAR struct tls_info_s *tls;
 
-  DEBUGASSERT(mutex->flink == NULL);
+  if ((mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0)
+    {
+      tls = tls_get_info();
+      DEBUGASSERT(mutex->flink == NULL);
 
-  /* Add the mutex to the list of mutexes held by this pthread */
+      /* Add the mutex to the list of mutexes held by this pthread */
 
-  nxmutex_lock(&tls->tl_lock);

Review Comment:
   When the thread exits, pthread_mutex_inconsistent is invoked.
   If the thread holds the mutex, other threads cannot modify mutex->link, so 
there is no race condition.
   If the current thread does not hold the mutex, tls->tl_mhead must be NULL; 
hence, there is also no race condition.
   <img width="440" height="292" alt="image" 
src="https://github.com/user-attachments/assets/0fdce007-50d3-42e8-ba46-aa8b8db295f4";
 />
   



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