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


##########
sched/sched/sched_unlock.c:
##########
@@ -69,10 +69,12 @@ void sched_unlock(void)
        * then pre-emption has been re-enabled.
        */
 
-      if (rtcb != NULL && --rtcb->lockcount == 0)

Review Comment:
   This task exists the sched lock at --rtcb->lockcount. Between that point, 
and the enter_critical_section below, there is a chance for an interrupt, which 
could trigger a re-schedule on this CPU,  leading this task to get scheduled 
out or migrate to another CPU
   
   It is better to take the critical section already before setting lockcount 
to 0.
   
   The issue doesn't occur when sched_unlock is called from semaphore code, 
since there we are already inside critical section. But from other places it 
happens.
   



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