Mike Higginbottom

A Digital Garden - frequent growth but a bit weedy in the back corner

You Need An Interrupt Service Routine

I was looking over some old notes this morning and I came across some stuff about interrupts.

For those not in the know, the phrase ‘Interrupt Service Routine’, often referred to as an ISR, refers to a quick set of low-effort steps that are executed when some event (an ‘interrupt’) needs dealing with that’s originated outside the current task that’s being executed.

One of my notes says, “Used on single processor systems to transfer processing”.

Given the terrible cost us overly hubristic humans pay for our confidence in our multitaking abilities, that kind of hits home a bit really.

Another note says, “Interrupts can be disabled and then restored to enable a code block to execute whilst protected from them.”

Well, wouldn’t that be a handy dandy thing to have in real life?

And then, of course, cogs start grinding and I’m like “Well why the hell not?”

So here it is, my prescription for a bit of self-medication (and you can pop some pills with me if you like) is to take stock a bit. What are my interrupts? Do I have decent ISRs in place to handle them?

You should normally be working in the system process, the main thread, the important and urgent thing that needs your focus and attention. But sometimes you get interrupted; by a new thought, possibly related to what you’re working on, that occurs to you, or maybe by an alarm or calendar event or phone call or child or cat.

The aim of the ISR is to capture this incoming information with minimal effort, ideally automatically. Processing that information comes later. All the ISR has to do is store the task somewhere that will get checked at some later point in time.

The idea here is to minimise distraction. The ISR should get out of your way as quickly and painlessly as possible.

A crucial part of getting out of your way that is not obvious is that you should have complete trust in your ISR to do its job. If you’re worrying about whether you’ve missed some incoming information, you’re distracted from the normal system process and the ISR is not doing its job properly.

The way to get this working is to list out all sources of events and then find a way to handle each of them with the least amount of effort so you can crack on with the important stuff.

A lot of things you can log and defer. For example an idea that comes out of work you’re currently doing. Note it down, defer it and carry on.

But some things you have to process then and there. Phone calls usually need answering, but you can sometimes afford to just let it go to voice mail. Kids should really take your attention away though to be fair. Cats though? Nope. Fuck em. They can wait.

So, write down a list of all your interrupts. Think about how you minimise them. And then write down what your ISR is to handle the remaining ones. Get this stuff squared away with a bit of discipline and you’ll carve out a good bit more distration free time.