High-priority Thread
CS Thinking
“Dad, you’re blocking my high-priority thread” my 7-year old son Arthur complains as I tell him to wash his hands before eating.
“No,” I explain patiently, “eating is a relatively low priority thread as you can last for several weeks without food. Drinking is a higher priority thread because you can only last for a few days without water.”
However, I do admit that I am blocking his eating thread. By which I mean that I am stopping him engaging in the task of eating until he has completed the task of washing his hands. Washing hands is a pre-condition to eating that I assume many parents place on their sometimes grubby children.
So why am I using the language of concurrent programming to talk about every day life to a young child? I can imagine that, when he’s older, my son’s answer might be that I like the sound of my own voice too much! The more charitable explanation, is that it’s my first simple example of how “Computer Science (CS) thinking” can be useful far outside the narrow context of talking about computer programs.
Time Management
It’s cliched and my 7-year old son might not yet realize it, but time is precious. Thinking in terms of threads and blocking, can help minimize the amount of time you waste. A few minutes here and there can quickly add up so that you have more time to devote to the things you really care about. So let’s look at another example.
Get funge’s stories in your inbox
Join Medium for free to get updates from this writer.
Pretty much every time my son gets into the car with food I have to remind him to put on his seat belt first. Aside from a chance to express my exasperation over how many times I have to tell him the same thing, this is another good learning opportunity. So long as he is unbuckled, he is blocking the driving thread since we can’t go anywhere until he is securely fastened. But it’s also a great example of the advantages of parallel processing. So long as he unblocks the driving thread, by fastening his seat belt, then we can proceed in parallel. He can eat while I drive. The alternative, that seems to be his first impulse, is that we first wait until he finishes eating, then he buckles up, and then we drive. It’s the staggering inefficiency of this alternative that makes me so incredulous that he can’t figure out on his own to put his seat belt on first.
Riches and Success
Hopefully this blog will be useful and help you be more efficient and find more time in your busy lives to spend on the people and activities you love. You may, however, be thinking that none of this seems like a big deal. You might think that my son is a hungry growing boy and so I should perhaps just be more patient. Nevertheless, by understanding the underlying concepts you can apply the same ideas to problems beyond every day life. For example, if you remember the world before Starbucks, you may recall lining up in a long line at your local coffee shop waiting forever to buy a bottle of water. The hold up was because old-fashioned coffee shops ran with a single thread. You go to the person at the register, request a latte, and then they stop serving other customers while they go off and make it. The “latte making” task then blocks the “serving other customers” task and the result is a long line of frustrated customers. Or, in the language of concurrent programming, there is resource contention for the coffee shop employee’s attention.
Starbucks recognized the problem and realized that by having a separate person to make espresso drinks, they could run two threads in parallel. In Starbucks, when you order a latte the task is off-loaded to another thread. Someone else makes your drink while the person at the register quickly takes your money and moves on to serving the next customer. If all you want to do is buy a bottle of water, the wait in line at Starbucks is usually a lot less than in an old-fashioned coffee shop. Soon, they may even have edible pastries!
Poor CS Thinking
CS thinking can therefore be the path to riches and success. But even the most efficient companies can still make mistakes. FedEx is usually the epitome of efficiency and it has served them well in their rise to the top. However, I recently had the misfortune to use their Office Print Online service while I was waiting for a new printer to be delivered at work. Everything worked perfectly until it was time to go pickup my print out. I had even managed to pay online so all I had to do was go to the FedEx store to collect it. When I arrived, there was only one person in the line in front of me. A FedEx employee was helping him pick the right card stock for some art project or other he was working on. The process was taking forever, and all I wanted to do was pickup my print out before I had to go pickup my kids from school.
“You’re blocking my high-priority thread!” I wanted to scream at the employee, but of course he wouldn’t know what I was talking about. His instructions were obviously to treat whoever he was dealing with as the only person in the world. In the language of concurrent programming, the customer in front of me had a lock on the employee shared resource and I had to wait until he released his lock. Or alternatively, I could ask the gentleman in front of me if he could temporarily release his lock. Although I obviously didn’t phrase it in those terms, I did eventually ask if I could quickly interrupt to pickup my print out. He kindly obliged and after pointlessly waiting for over ten minutes I was on my way in only another thirty seconds! Needless to say, I will never use the printing service again since needlessly locking a critical shared resource for long periods of time while other threads (i.e. me quickly trying to pickup my print out) have to wait indefinitely is not good CS thinking!
Big Picture
A recurring theme throughout this series of blogs will be taking ideas and concepts from Computer Science and explaining them in every day life situations. Next time, I’ll describe how CS thinking can be applied to company culture and human relationships!
Acknowledgements
Thanks to Kathleen Kovatch for feedback on early drafts of this post and to James Cham for originally suggesting that I turn the CS Thinking ideas into a blog.









