Monday, April 22, 2013

Multitasking! (Part II)

The other day, in Multitasking?, we talked about the mythical multitasker: a person with the ability to simultaneously undertake several activities without compromising any of them. I suggested that multitaskers are in fact quite rare if not altogether mythical and that almost all who claim to be multitasking are in fact, not. I further proposed that the rarity of true multitaskers didn't necessarily mean that more could not exist, but that instead, someone who lacked multitasking skills might acquire them through training and practice.

Ear of Corn
You're about done with dinner. There's little left over to become leftovers. All but one item of food, a solitary ear of corn, have been consumed. Each of your two kids realizes that the other may intend to consume it. Simultaneously, each rises from her chair and dives across the table, reaching desperately for the last ear.

Two kids plus one ear of corn equals "resource contention". Resource contention is the primary reason for multitasking. The only real diference between you trying to multitask and your two kids vying for an ear of corn is the contested resources. In the case of multitasking, the contested resource is you. Therefore, viewing an ear of corn as the contested resource is a great way to start to understand multitasking.

Ultimately, multitasking is about resource management and allocation. The better you manage and allocate your resources, the less contention. If you get really good at it, you can appear to be to expertly performing many complex tasks simultaneously, even though you never actually simultaneously do any of them.

Seeing the Contest
A prerequisite for good resource management is seeing that the resource is contested. It's hard to do resource management well when you're not aware that there are contested resources.

You get up to clear the table. Your kids grapple on the floor each reaching for an unidentifiable yellow object that just rolled under the couch. You might see them, you might not. Seeing them, you might say, "Hey, you two have fun while I clear the table", or, "Hey, what are you two fighting over?", or, "Get up off the floor and leave that ear of corn for the dog."

Sometimes you don't know that a resource will be contested until the contest begins. Other times (e.g., the second time for pretty much anything), you can anticipate the contest. Whether reactive or pro-active, resource management begins with awareness of the contest or its potential.

To Act, or Not
Once you know that you have a contested resource, the first question is whether or not you want to do something about it. Even though you prepared an odd number of corn ears for an even number of corn consumers and even though it quite predictably led to resource contention, dealing with the contention is not necessarily your problem.

A quite reasonable response to the contention is to actively do nothing; let the contestants work it out. Oftentimes your greatest challenges in resource management may have been facilitated by you. Why would others manage the contest when you always do it for them? This applies to all types of resource including ears of corn, and specially, you.

Managing the Resource
Let's say that you decide to manage the contest. Tere are many ways to go about it.

What Resource?
The simplest way to manage the contest is to never make the contested resource available in the first place. For an even number of corn consumers, your prepare an even number of corn ears, or for any number of consumers, you prepare some whole-number multiple of corn ears.

In these examples, even if there is a contest, it's likely due to someone having "cheated" or taken more than his "fair share". The violations are easy to see. This makes the contest something that can be readily managed by the contestants.

Of course, the easiest method of all is this. Regardless of the number of corn consumers, you prepare zero corn ears.

Micromanagement
One of the more common forms of resource management imposes an overhead cost that typically exceeds 100% of the original. It's called micromanagement.

You grab the ear of corn from your kids and sit them down at the table. You walk into the kitchen, cleanse the corn ear of dust balls and dirt. You return to the table with it, a plate and a knife.

One by one, you strip the ear of each kernel alternatively allocating the kernels to one of two piles that form on either side of the plate. As you do so, you count, "One for Rya, one for Nilo. Two for Rya, two for Nilo..."

An hour later, you look up to see both kids have fallen asleep. You pick up the plate and toss it in the fridge. They can have corn for breakfast.

Macro-Management
If you want to save yourself some time, skip micromanagement and go for macro-management. Instead of allocating the corn one kernel at a time, you grab either end of the ear and break it in two. You hold your hands behind you back and let one child pick the hand that holds the ear she wants. You then present that ear to the other child, and the second ear to the first.

While the amounts of resource shared may vary, macro-management provide significantly greater efficiency than micromanagement.

Timesharing
An alternative to directly managing a resource is to manage time spent with it.

You place the ear of corn on a plate in the middle of the table. You instruct the kids that you will count to ten after which Nilo can take the ear and gnaw on it while you count to ten. When you reach ten, Nilo must return the corn to the plate. Now it's Rya's turn. She takes the corn. You count to ten. Back to Nilo.

Timesharing is a core technique used by computer operating systems to facilitate multitasking. The UNIX operating system was originally called the UNIX Timesharing System.  Timesharing can make resource management easy; however, there are several issues that occur in its most basic form, e.g., counting to ten.

Readiness
You reach ten and it's time for Nilo to surrender the corn ear. Only problem is that Nilo hasn't yet taken a bite. He's been holding the corn as if ready to do so, but his mouth is so full that he can't fit in any more.

You tell Nilo to return the ear to the plate. He tries to complain, but his words are garbled by so many kernels. He pouts and chews vigorously as he surrenders the corn.

A problem with timesharing is that fixed periods of time don't always work simply because the potential user of the resource isn't ready to use it. This is the case with resource management generally. It isn't necessarily your problem to fix, but certainly one of which to be aware. You make the resource available; if it can't be used, so be it. More resource for others or for you.

Time Allocation
If you want to make available resources only when the consumers are ready to use them, you might want to consider forms of time allocation more advance than fixed periods.

For example, rather than alternatively providing ten-second intervals to either child, you simply provide a ten-second interval every sixty seconds. Whichever child is ready first, gets the upcoming interval.

During the fifty-seconds in which no resource interaction is permitted, you can do whatever you want.

Fair-share Scheduling
You can implement a form of micromanagement that puts the overhead burden on the corn consumers. Rather than you dolling out the kernels, you let the kids do it. Each takes the ear of corn and removes a kernel. She then passes it to the other who does the same.

Merit-based Management
Perhaps my favorite form of resource management is merit based. In short, the amount of resource provided to a consumer is consistent with the consumer's deservedness of it.

Of course the rules of merit can become a new point of contention. Still, if the resource is owned by you or is you, you can make them up arbitrarily.

Who gets more corn? The child who's the hungriest? The child who's the smallest? The child who's the biggest? The child who cleared the table? The child who said "please"?

Up to You
Whether or not you see the contest, whether or not you choose to manage the contest, and how you manage it are all up to you. Regardless, knowing how to manage contested resources is the first step in becoming a good multitasker.

Next time, we'll get into the deeper magic of simultaneity.

Happy Monday,
Teflon

No comments:

Post a Comment

Read, smile, think and post a message to let us know how this article inspired you...