jlaitine commented on code in PR #16194:
URL: https://github.com/apache/nuttx/pull/16194#discussion_r2059578589


##########
sched/semaphore/sem_wait.c:
##########
@@ -218,6 +271,16 @@ int nxsem_wait_slow(FAR sem_t *sem)
 #endif
     }
 
+  /* If this now holds the mutex, set the holder TID and the lock bit */
+
+  if (mutex && ret == OK)

Review Comment:
   Yes, thanks for asking, the discussion clarifies things for others as well.
   
   I believe the only "sane" place to set the mutex holder TID is really when 
it gets out of sem_wait and really holding the mutex. This  is after all the 
priority adjustments and what not.
   
   Setting it in sem_post is more dubious, but it must be set to something else 
than the TID which just posted. One could arque that the most proper value to 
set in sem post would be "NXSEM_NO_MHOLDER | NXSEM_MBLOCKS_BIT", since at that 
point no other threads who have acquired the mutex are running. However, this 
would require special handling again in sem_wait; if while everyone, who 
acquired the mutex before, are blocked for some reason and some other thread 
blocks on the mutex again, one would need special handling for that value. So 
basically, setting *any* TID from waiting list is fine - you don't *really* 
need to know which one of those will wake up. Picking the one from the top of 
the waitlist is basically the same thing as what is done with counting 
semaphores.
   



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