Page 1 of 1

does scheduling a callback preclude disabling interrupts?

Posted: Thu Mar 19, 2020 6:11 pm
by smhodge
I am using the <schedule> method to make an interrupt append an "event number" to a list. Works fine, no problem. My question is when I later on in the top-level code pop an event number off this "stack" do I need to globally disable/re-enable interrupts while I do this? I am suspecting that I don't have to. Is that correct?

Re: does scheduling a callback preclude disabling interrupts?

Posted: Fri Mar 20, 2020 2:28 am
by jimmo
I think we'd need more information about the rest of your program. i.e. is your stack a high-level thing that can handle being pushed while it's in the middle of being popped?

schedule will cause the scheduled code to be executed synchronously between two VM instructions at some point in the future.

So it's not so much the interrupt handler that needs to be disabled but that your scheduled push code might be happening right in the middle of a pop. Disabling interrupts might not help because the scheduler can still run a previously scheduled event.

Instead you might want to do something like have a flag to "protect" the stack. If the push function (called by the scheduler) sees this flag set, then it can re-schedule itself. The pop function can set this flag while it's doing the pop.

Re: does scheduling a callback preclude disabling interrupts?

Posted: Fri Mar 20, 2020 4:00 pm
by smhodge
Thanks, I'll use your flag suggestion.