Reputation: 1
What would happen if I use semaphore and mutex locks in interrupt context? Normally semaphore is used in synchronization mechanism. What would happen if I use this one in an interrupt context?
I am working on a project on gpio pins and when interrupt happens, I have to send one signal in ISR. I am using spinlocks.
What would happen if I use semaphore and mutext in ISR?
Upvotes: 0
Views: 1093
Reputation: 65928
Waiting in mutexes and semaphores are implemented using switching current task state to TASK_INTERRUPTIBLE
/TASK_UNINTERRUPTIBLE
and similar with futher call to schedule()
.
Calling schedule()
with current task state differed from TASK_RUNNING
leads to switching to another process. And if current
refers to interrupt context, you will never return back to it, because scheduling can switch only to the process.
So, when you lock contended(that is, currently locked) semaphore/mutex in interrupt context, you just lost current execution "thread".
If you lock semaphore/mutex which is uncontended(currently not locked), execution will be correct except warning in system log about improper semaphore/mutex usage.
Upvotes: 1