In: Computer Science
Why is it dangerous to acquire a lock in an interrupt handler?
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
Main problems come when we use locks which go to sleep if the lock can't be obtained, the semaphores. when you try and lock a spinlock, it does not go to sleep, rather it "spins" in a loop trying to lock over and over, this is called busy waiting. obviously, anyone who obtains a spinlock should be very quick with it, or someone else is going to be spinning aimlessly and hogging CPU. on the other hand, if you try and acquire a semaphore that's not available, you will be put to sleep - and that is why can't try and lock a semaphore from an interrupt handler. interrupt handlers are not allowed to sleep, why? b/c sleeping requires the context of a process - the functions you call to invoke a sleep all operate on a globally exported kernel variable called current, a pointer to the currently executing task's task_struct. this pointer is not valid in interrupt code, so if you try to use it by calling a sleep function, ur system will die.
Kindly revert for any queries
Thanks.