Concurrency IV -- Spinlock, may be used in code that can't sleep
Pinciples for using spinlock
1. CANNOT sleep when holding a spinlock
2. disable preemption before holding a apinlock
   this is done by kernel, the spinlock code itself
3. disable the interrupt on the local cpu only
4. hold the spin lock in minimum time
   If you have a spinlock that can be taken by code that runs
   in (hardware or software) interrupt context, you must use one
   of the forms of spin_lock that disables interrupts. Doing
   otherwise can deadlock the system, sooner or later. If you
   do not access your lock in a hardware interrupt handler, but
   you do via software interrupts (in code that runs out of a
   tasklet, for example, a topic covered in Chapter 7), you can
   use spin_lock_bh to safely avoid deadlocks while still allowing
   hardware interrupts to be serviced.
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐