It may not always feel like it, but operating systems are extremely good at multitasking. When your OS is running without a hitch you can shop for new sneakers, listen to a podcast, back up your photos, and finally respond to that email from your landlord all while waiting for your code to compile. That’s not to mention all of the monitoring and calibrating that goes on behind the scenes, all the beating and breathing and blinking that keeps a computer running with no conscious effort from the user.
But much like me when I used to watch America’s Next Top Model while doing my homework in high school, the OS only actually focuses on one thing at a time. The processor executes instructions serially (although if you have a new-ish computer it probably has 2-4 cores or processors).
This feat is accomplished by really smart scheduling. The OS switches out tasks like a hyperactive DJ, giving higher priority to processes that are interactive and need a quick response (video games are a good example). Short jobs also get a bump in priority, the same way you cross the easy wins off of a to-do list first.
OS schedulers optimize for several different metrics: fairness, response time, overall turnaround time. They also have to consider starvation. Starvation happens when one job never gets run, typically because it gets stuck at the end of the queue and higher priority jobs keep getting added in front of it. The starved job never makes any progress for lack of resources. It just keeps waiting and waiting for its number to be up, and it never is.
I think about starvation whenever my laundry basket begins to overflow. Or when I forget a friend’s birthday, or pick up my guitar to find it dusty and out of tune.
In the context of operating systems, programmers have found a reasonably good solution to this problem. All jobs periodically get boosted to the top of the queue so they’re guaranteed to run for a few cycles every once in a while, even if it means taking time away from a high priority job.
This strategy doesn’t exactly translate to my neglected laundry situation because computers context switch (pivot from one task to something completely different) very quickly and reliably. Humans struggle with that, which is why I’m probably not going to learn the violin by picking it up one minute a day for ten years. But the general idea of blocking off a chunk of time every now and again to step away from the grind and focus on “low-priority” items feels like a good one.