xiaoxiang781216 commented on PR #15705:
URL: https://github.com/apache/nuttx/pull/15705#issuecomment-2623667231

   > The current API definition is perfect, and the function name can identify 
the implementation details of each function.
   > 
   > ```
   > spin_lock: spin lock
   > spin_lock_nopreempt: spin_lock + sched_lock
   > spin_lock_irqsave: spin lock + irq save
   > spin_lock_irqsave_nopreempt: spin_lock + irq save + sched_lock
   > ```
   > 
   > And your expected API
   > 
   > ```
   > spin_lock: spin lock + sched_lock <--- why?
   
   so, you don't read my reply carefully, let me copy the example again:
   
   1. thread0 on CPU0 hold a spinlock without hold sched lock
   2. thread1 on CPU1 wake up thread2
   3. OS decide suspend thread0 and resume thread2 on CPU0
   4. thread1 on CPU1 want to hold the spinlock hold by thread0
   but thread1 is ver hard to know when it can finish the busy wait loop since 
thread0 is already in the suspend state.
   so, it's VERY VERY dangerous to schedule a thread which hold a spinlock.
   
   and the issue I mention before: 
https://github.com/apache/nuttx/issues/9531#issue-1755306015
   spin lock can't use standalone without sched lock.
   
   > spin_lock_preempt: spin lock <--- why?
   > ```
   
   same it is unsafe, should be used with the caution.
   > 
   > nuttx is not Linux, please do not introduce the old implementation in 
Linux into Nuttx
   
   This behavior isn't Linux specific, ALL OS support spin_lock must disable 
schedule too, otherwise the deadlock will happen naturally. Please reread the 
above case again.
   


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