Saturday, April 5, 2008

Getting things done? Check!

As I wrote in the last entry, polling can be used to promote procrastination. Here, I'm planning to address another useful tool: Multi tasking.

Multi tasking is the art of performing multiple tasks at the same time. It has the interesting property that you're almost guaranteed to perform each task less well than you would if you had performed them one after the other.

Method 1: Cooperative multi tasking
Cooperative multi tasking works much like polling. Every so often you break off from your task to check if there's anything else that needs to be done, then do that for a while, until again checking. If there's only one task to do, you'll check and immediately get back to what you were doing. Embedded systems sometimes work like this, because it gives complete control over where things are interrupted, and can in theory give very good performance. In the real world, this can be used, for example, for talking to multiple people at the same time in a chat system. By switching slowly between them, you will be able to keep up the semblance of a conversation with a large number of people. Another example would be switching from one task to another whenever the task becomes difficult or stressful. This practically guarantees that nothing will ever get finished, and also teaches a healthy habit of avoiding difficult problems and working on easy tasks.

Method 2: Time slicing and preemption
Time slicing relies on an interrupt firing every so many "ticks", giving control to a scheduler that picks a task to run for the next "time slice". Interactive computer systems use this, with an appropriately short time quantum, to provide the illusion of performing multiple tasks at the same time. If the time quantum is too large, the illusion will not be upheld, and if too short, the overhead associated with switching tasks will dominate the real work. In modern computer systems, where locality of reference in the caches (TLBs as well as instruction and data caches) is important, switching quickly also makes the temporal locality so poor that the cache brings little benefit. The human mind, working much like the memory hierarchy in a computer, will also be made more inefficient by switching rapidly between different cognitive tasks. You can use rapid, regular switching between tasks to make sure that you never spend long enough on a task to internalize it and make significant progress.


No comments: