I'm having a hard time figuring out the best way to implementation synchronization when it involves an hardware interrupt handler and some process code.
The problem I see is that interrupt hanlder will not be interrupted. Here is an exemple:
Code: Select all
irq_handler:
lock
CS1
unlock
A:
lock
CS2
unlock
If lock is implemented using a spinlock and the interrupt is launched just after A locked the code, it'll never go out of the interrupt.
On one of the cases, I implement a simple solution using Test-And-Set, but at this point there was only one process that could wait. What if I would like to implement a sleep queue where threads are woken from the sleep queue from an interrupt ? For instance, if process A is trying to add itself to the queue and at this point the queue is modified by the interrupt handler that modifies also the queue, we may have a problem with the state of queue.
Is there a synchronization primitive that works well in these cases ?
Or is it necessary to think of ways to solve each problem individually ?
Thanks
Baptiste