spin_lock on non-preemtive linux kernels

前端 未结 4 1196
忘掉有多难
忘掉有多难 2021-01-14 02:56

I read that on a system with 1 CPU and non preemtive linux kernel (2.6.x) a spin_lock call is equivalent to an empty call, and thus implemented that way.

I can\'t un

4条回答
  •  滥情空心
    2021-01-14 03:24

    To answer the two parts of your question:

    Even on non-preemtive kernels interrupt handlers may still be executed for example ...

    spin_lock() isn't supposed to protect against interrupt handlers - only user context kernel code. spin_lock_irqsave() is the interrupt-disabling version, and this isn't a no-op on a non-preemptive uniprocessor.

    ...or I might call a function that would put the original thread to sleep.

    It is not allowed to sleep while holding a spin lock. This is the "Scheduling while atomic" bug. If you want to sleep, you have to use a mutex instead (again - these aren't a no-op on non-preemptive uniprocessor).

提交回复
热议问题