Showing posts with label Ferr. Show all posts
Showing posts with label Ferr. Show all posts

Monday, June 13, 2011

Bog Dragons Do Not Support Multithreading

Multithreading is a technique in modern computer architectures to process multiple sets of instructions on a single CPU core. Different sets of instructions run in different threads, and the operating system switches between these threads. Unlike multi-core or multi-processer systems, multithreaded systems are not actually running these sets of instructions in parallel (at the exact same time). Instead, a single CPU core is rapidly switching between the threads to allow each to make progress.


The ability to multithread instructions allows modern computers to effectively do work "in the background". For example, the spell check operation in a word processor might run in a separate thread, allowing the user to continue to work as the full document is being spell checked. In the absence of multithreading, computationally expensive operations can cause the entire computer to "freeze" as the CPU is stuck on one task.


Ferr dove low as another bog lizard snapped at her from a nearby tree branch. She hated traveling through the bog. It was filled with nasty creatures, and it always smelled like… a bog. At least there was only a few miles left to go. She would be home in time for dinner. For a brief moment, Ferr let her mind drift and wondered what dinner would be.


Then, Ferr heard a loud screech. The sound sent a chill through her. It was a bog dragon, and it sounded hungry.


Bog dragons are particularly vicious creatures, especially with respect to fairies. In fact, fairies seemed to be either their sworn enemies or their favorite snacks. Nobody was really sure which it was. Regardless of the dragon's motivation, Ferr knew that she was in grave danger. She took off flying as fast as she could.


Ferr dodged trees as she flew through the swamp. Unfortunately, bog dragons are much smaller than regular dragons, being about the size of a house cat, and thus are able to maneuver quickly in the dense swamp. Ferr knew that she had little chance of winning this race. The bog dragon was both fast and familiar with the swamp. It was only a matter of time before it caught up to her.


Her mind raced, trying to find anything that would save her. She mentally ran through the list of all of her spells. Nothing seemed promising. She cursed herself for having not perfected any defense spells against a bog dragon. Bog dragon sightings were rare enough that she had never made it a priority. Now, that seemed like a mistake.


She could hear the bog dragon breathing behind her.


Distracted by the sound and her own thoughts, Ferr clipped a tree. Her left wing missed a beat, and she was thrown off balance. She spun through the air, trying to regain control. But, it was no use. She had been flying too fast. She barreled into the soft mud with a loud squish, sliding fifteen feet. She was coated from head to toe in brown bog mud.


Above her, the bog dragon circled eagerly.


As she scolded herself for not paying more attention, a memory popped into her head. Bog dragons were not multithreaded. They could not multitask. They could only ever do one thing at a time! No matter what it was, that one thing would occupy their full attention. Right now, the dragon was doing one thing: hunting her. But, if she could distract it with some other task, it would not be able to context switch. She could escape.


Ferr ran through the list of spells again in her mind. Finally, she hit upon the perfect solution: the spell of Mental Flash Cards.


Ferr had used this spell on herself to prepare for her finals last year. When cast, it ran through five minutes of simple math flashcards in the back of the target's mind. Ferr would use this to practice math while flying to school. Since the math was simple, she could balance the two tasks. She would quickly solve each flash card and then concentrate on flying: one card, one beat of her wings, one card, one beat of her wings, and so forth. As long as she switched between the tasks, she could do both safely. But, the bog dragon could not.


Hoping that she was remembering this characteristic of the bog dragon correctly, Ferr cast the spell. If she was mistaken, and the bog dragon could multitask, then giving it math flash cards would probably just anger it. It would be like having someone rudely scream "WHAT IS 1 + 3?" in your ear every few minutes. Nobody enjoyed that.


Three seconds later, the bog dragon flew directly into a tree. It fell to the ground with a squishy thud.


The spell had worked. The bog dragon was fully occupied with the flash cards. It was unable to switch between the flash cards and flying.


Ferr did not waste any time. She was up and flying immediately. The five minutes would give her enough time to escape.


Ferr looked back once. The bog dragon was lying on the ground looking miserable. Ferr could not feel too bad. After all, she would have been the dragon's lunch. And even though the dragon had lost its lunch, at least it would learn some simple math in exchange.

Monday, May 30, 2011

The Fairy's Sandbox

Sandboxes are isolated computational environments used for testing or security. For example, a testing sandbox may be a clean installation of a particular operating system and configuration, allowing you to control for the testing environment. Using a sandbox allows you to run code in an environment different from your development environment. Further, a sandbox protects the rest of the computer from potentially harmful effects of the program.


Ferr had barely slept all week. She was too excited. She had been waiting for this day for years. Today was the day that Ferr would finally learn to use her magical powers.


As the youngest fairy in a very large family, Ferr had always been jealous of her older siblings as they flew about and cast various spells. She longed for the day when she too could turn unsuspecting travelers' shoe-laces into worms. That was one of the best parts of being a fairy. Of course, like all young fairies, Ferr had never been permitted to venture outside of the safety of the magically protected kingdom. But, she had heard stories, and they sounded wonderfully fun.


Ferr arrived early to her first lesson. The first hour of the lesson was classroom instruction that reminded Ferr of her "History of the Fairy Kingdom" class. It was horribly dull. The instructor lectured in front of the class in a monotone voice about the origins of fairy magic and the importance of safety. Ferr had heard all of this before. She wanted to get onto the actual magic.


After the introductory lecture was done, Ferr's mentor took her to a practice room buried in the back of the school building. The room was nothing like Ferr had expected. It was a large, but simple, concrete room. It was furnished with a simple wooden table, two plain wooden chairs, a bright plastic beach ball, and a small potted flower.


"What is this place?" asked Ferr. She looked around nervously.


"It is a sandbox." responded her instructor as though that fact should be completely obvious.


"A sandbox?" asked Ferr. She had never heard of this before.


"Yes. You didn't think that we would let you try your magic in the middle of the kingdom, did you?"


"No… but… This does not look magical at all."


Ferr's mentor laughed. "Of course it is not. It is an ordinary room. You supply the magic."


"But, it could at least look magical." protested Ferr.


"The room is simple. That is the important part. You'll see."


Ferr was not sure what the last statement meant, but she let the topic go for now. She followed her mentor over to the center of the room and sat in one of the two chairs.


"First," her mentor began. "You are going to change the color of these flowers from blue to red. Do you know how to do that?"


Ferr nodded eagerly. She had seen her siblings practice changing the colors of flowers all the time. She cleared her mind and tried to concentrate. She gave her wand a quick flick at the flowers.


A large splotch of dark red appeared on the opposite wall. Ferr gasped. She had missed the flowers and stained the wall!


"Oh no!" she cried.


Her mentor did not appear upset in the least. "Try again, but keep your wrist tighter." she instructed.


"But… the wall?" asked Ferr. She had stained the wall. Was she going to be kicked out of school for this? Or banned from using magic? A scary parade of horrible scenarios marched through Ferr's mind.


Her instructor glanced back at the stain. With a quick flick of her own wand, the stain disappeared. "That is why we are in a sandbox." she added.


Over the next hour, Ferr saw the wisdom of the sandbox. Her incorrect spells repeatedly stained, scorched, and pummeled the simple room. To an outsider it would probably have looked as though Ferr had a vendetta against the room itself. But, each time, her mentor calmly restored the room to its previous state. And after 4 hours of practice, Ferr had even managed to turn the flowers a slight purplish.


The rest of the month was the same. Simple spells turned out to be surprisingly hard. And, Ferr repeatedly destroyed the room until she mastered them.


One morning a new surprise awaited Ferr. There, on the table, was a small lizard with a terrible temper. It hissed at her and tried to bite her repeatedly.


"I thought bog lizards could not get through the kingdom's magical protections!" yelped Ferr as it lunged for her. The creature's breath left no doubt that this was indeed a bog lizard.


"They cannot." agreed her mentor. "But we can bring them in here. This room is isolated from the rest of the kingdom. So, we can bring in all the dangerous creatures that we would not want to have running around wildly. You do need to practice dealing with unpleasant creatures, you know."


During that day's class, Ferr reached a new level of room destruction. She even managed to shatter the table. But ultimately, she learned to charm the lizard so that it would not hurt her. Still, the creature's horrible breath made her eager to finish up early.


It took a full year before a junior fairy was allowed to use magic outside of the sandbox, and now Ferr understood why. Ultimately, Ferr gained mastery of her skills and the destruction stopped. She was allowed to start using the magic spells that she had mastered within the sandbox. However, the original glee was replaced by a wiser feeling of caution.


And, Ferr always made sure to test new ideas in a sandbox. She would hate to accidentally turn the wallpaper in her room into fly paper as her older sister had done.



-------------------------


If you are interested in learning more about the importance of testing, check out the story of why it is important to always unit test your magic spells:

http://computationaltales.blogspot.com/2011/05/importance-of-unit-testing-magical.html