Sunday, August 17, 2008

Asynchronicity Theory

Asynchronicity implies multithreading. While working in our restaurant's kitchen, we notice that we are running short on milk. Not having the time go and get more from the corner grocery store, we ask our boss boy to do it for us, and instruct him to store the milk in the refrigerator when he gets back. We are now two persons doing work for the kitchen, in the same way as if we had spun off a worker thread to call a lengthy method asynchronously.

Multithreading requires synchronization. We are now preparing sophisticated deserts for tonight's dinner. As soon as one is completed, we cautiously store the precious creation in the refrigerator. As we place one on the bottom shelf, our boss boy gets back from the grocery store, and drops the milk we asked him on the same shelf. Ouch, one desert less... maybe we should avoid using the refrigerator simultaneously next time.

The moral of this story: Asynchronous callbacks are serious stuff, as they imply the utilization of multiple threads, and the synchronization of the resources accessed by these threads.

No comments: