0

I am new to Linux device driver programing, please help me out.

I was doing some little experiment, then i came with strange output. For some reasons i have kept mutex_lock(system) in interrupt handler. In other function (let us call func1) i have kept mutex_lock(system). While executing func1, before mutex_unlock(system) interrupt is occurring. So theoretically dead lock should occur. But its not happening.

I want to know how exactly its working?

  • Does this answer your question? [Linux Kernel Preemption during spin\_lock and mutex\_lock](https://stackoverflow.com/questions/6555358/linux-kernel-preemption-during-spin-lock-and-mutex-lock) – stark Nov 03 '20 at 13:38
  • 2
    mutex may not be used in IRQ context. The exception when IRQ is threaded (usually in RT environment), in that case it's acting like a normal lock, i.e. *first takes — first uses*. – 0andriy Nov 03 '20 at 14:59
  • @stark, Thanks for the response, No it didn't, My question is "when an interrupt occurs while executing func1 after mutex_lock(system) and before mutex_unlock(system), interrupt handler will be called. But my interrupt handler also have mutex_lock(system). So theoretically dead_lock should happen. But its not happening in my case. Is there any idea why dead lock is not happening???" – Balasubramanian L Nov 04 '20 at 05:32
  • @0andriy, Thanks for the response, I was doing some experiment(Just to understand the behavior). I used lock in interrupt handler function so a dead lock should occur, but its not happening. Why? – Balasubramanian L Nov 04 '20 at 05:45
  • I believe mutex_lock calls preempt_disable – stark Nov 04 '20 at 10:54
  • When asking such question, try to enable all relevant `CONFIG_DEBUG_*` options in the kernel configuration. You will be surprised. – 0andriy Nov 04 '20 at 12:10

0 Answers0