Moe Computing Research Center (MCRC) – Harem Resource Management

As I dig up my research (and wiki page links) for this post…

whitehatazn-48.jpg This past week, my project released its complete design of the system to the government. Along with the system design review, the software group also briefed their software design. After listening to software’s boring presentations, I thought to myself: “There needs to be a better way to teach some of this dry stuff.” Remembering that I once wrote about tsundere state machines, I thought of the various ways I can teach computer science/engineering theory with anime again. Here’s the topic pairing I came up with for today: harems and operating systems.

Let’s review some basics. Resource starvation is the situation where a process cannot finish its task because it is constantly denied a resource it needs. Starvation is more likely to occur when more than one process are accessing the same resource. One form of starvation is deadlock where two or more processes are waiting for the resources held by another process to be released. Deadlock becomes an issue in concurrent computer systems because these systems often allow for mutually exclusive shared resources. A classic example of starvation and deadlock is the dining philosophers problem which is often visited in most college computer science programs.

Interestingly, harem anime can be analyzed using similar terminology. What makes associates harem anime to these computer science theories is the male lead. The male lead can be viewed as a form of a mutually exclusive resource. The females in the show can be viewed as processes which require the male lead resource. With these building blocks, models of resource management can be developed and the models may be subject to the situations of starvation and deadlock. Today, I’m going to take a look at what harem anime can teach us about these concurrency issues (as the MCRC continues to develop the TsundereOS for the Combat Waitress Project).

The concept of resource starvation is fairly common in harem anime. If the male lead is mutually exclusive, then he would only be able to interact with one female at a time. This leads to the possibility of starvation in the harem world since more than one female fight for the male. The most basic form of this model can be seen below:

The resource (Male Lead) is the rectangle. Processes (the girls) are the circles. Process requests for resources are the directed edges from the process to the resource. Since the resource is mutually exclusive, only one process can access the resource at any given time (in this case, Girl B currently possesses the Male Lead). Depending on how long the process holds the resource, resource starvation of the other processes may occur (Girl A and Girl C) and may need to be addressed.

What makes the harem resource models interesting is the number of girls after the main guy. A Negima-like process load would drive the system designer crazy (although one can argue Negi is not mutually exclusive). Even a more common harem process load (take Shuffle! for example) would require a bit of design to manage possible starvation.

Shuffle! has one of the most straightforward harem resource models. Excluding Mayumi, Ama and maybe Benibara, Shuffle! allows for at most five girls competing for the male lead.

Solving harem resource starvation is usually the same as solving for regular computer starvation. Scheduling algorithms determine what time the process is allowed to access the resource and for how long. Advanced scheduling algorithms not only reduce the possibility of resource starvation but also allows for process priority over the resources (e.g. if the resource is CPU time and the program is a single player video game, then graphics-related processes should receive more CPU time than the network-related processes). Harems can be modeled with similar scheduling algorithms.

Note that the best scheduling algorithms are only able to alleviate the problem of resource starvation and not completely fix the problem. In most real-world systems, there is always some limiting factor which creates the possible starvation (not enough cpu time, not enough memory, slow memory, slow network latency, etc.) Harems don’t need to have a robust scheduling algorithm since starvation for one girl usually a good setup to drive the plot along (think Mao from Kimikiss or the extreme cases of yandere with Kaede and Kotonoha).

I would argue that harems need to have some form of a scheduling algorithm to even out each girl’s time with the male lead. This is primarily for the audience. The audience will favor a different girl throughout the course of the show and her screentime paired with the male lead will make the audience content. Otherwise, the show may alienate some of its audience (like this Clannad fan who is still waiting for the Kyou OVA).

Just like CPU time models, harem anime can be modeled by who has the resource at what time slot (in this case by episode). Notice how most of the episode time is focused on Asa (not including her role in the Primula-Nerine arc). Harem scheduling often leads to the tricky problem of not pissing off their fanbase.

Harem resource management gets a bit more complicated with the situation of deadlock. In the most basic form of computer deadlock (two processes, two resources), both processes would end up starving for a fair bit of time. If neither of the processes timeout and release the resource it owns, then both processes will be stuck frozen. If both frozen processes are a part of the system core, then a system halt may occur (or in layman’s terms the “screen of death”).

The harem deadlock model is slightly different. Unlike traditional computer deadlock models where processes are competing for two or more separate resources, harem deadlock maintains the model of competition over one primary resource. However, the primary resource has more than one sub-resource in which competition for more than one sub-resource may lead to process deadlock. In harem anime, deadlock usually occurs when one or more girls fight for the lead male’s time. The recognition of not having enough of the male lead’s time usually initiates the competition for the remainder of the male lead’s time which may or may not be held by some other girl. If requests for more of the male lead’s time get consistently denied (starvation) and the other competing girls is known, then there’s a high probability that the traditional harem confrontation may occur.

The above is the classic deadlock situation found in ef. Kei wants to be more than friends and thus, wants Hiro’s time out of school. Miyako wants Hiro to give up the time going to school so he could follow his dreams as a mangaka and she want to be there with him when he does. This setup was a solid foundation for the following events in ef.

There are a number of ways to solve computing deadlock. Certain processes can be of a lower priority and could timeout if they are stuck in the denied state for an extended period of time. If the process model is simple enough, algorithms could be used to find the possibilities of a cylic-stop-and-wait conditions and proposes new process models which prevent deadlock. In most computing systems, there’s no complex implementation for solving for deadlock since the condition is bearable for the rarity of it occurring.

Solving harem deadlock is also slightly different than its computing counterpart.  One difference is that the guy could arbitrate who gets what himself. Another difference is the girl’s recognition of competition to the resource and may force the other girl(s) to release the competing part. Compare this to the computing world where most resources are static and processes usually have no knowledge of the other process’ state. Also, the girl may realize that she would never get the part she requests from the main guy and leaves (process timeout).

We can use classic techniques to prevent/correct harem deadlock. But why? Harem deadlock provides us with some of the most memorable scenes in the genre.

So what can you do with these models? Not much outside of the traditional computer models they represent. Harem resource models don’t stray too far from the computer science counterpart. Thus the harem models don’t reveal any new algorithms or implementation techniques. What these models do is to help teach some of the basics of operating systems. It’s a useful tool to help train new entry-level engineers for the MCRC and prevent lost talent to go to the Mecha Research Triangle… more or less…


5 Responses to Moe Computing Research Center (MCRC) – Harem Resource Management

  1. Ryan A says:

    Nicely done! 🙂 I’m actually in an OS course atm (which should have been taken last year).

  2. meganeshounen says:

    Starvation within a schedule of tasks can still happen, provided that 1) a certain low-priority task gets shafted by a higher priority task, and 2) other higher priority tasks come in consecutively. That would make the low priority task unprocessed for as long as higher priority tasks keep on piling on…
    A probable fix would be some sort of “priority adjustment” algorithm that somehow upgrades a task’s priority every time it gets denied time on the CPU….

    Anime-wise, it would be similar to Sia’s finishing episode in Shuffle! (post Nerine and Primula arc). She does get an episode or two to herself early in the series, but then, she gets denied major screen time afterwards. Somehow, her “priority” gets higher and higher and then, seeing how everyone has changed (including Nerine) she flips out into Kikyou, and… you know what comes after that. -_-

    A deadlock, though… realistically(?), when that happens to two girls who both favor a single guy, their rivalry might take a lot longer, in which two things might happen. They both tire of the protagonist, especially if the male lead is indecisive as heck (Manaka Junpei of Ichigo 100%?)… or the rivalry soars to two heights and we get a School Days anime ending. Yeah, Nice Boat.

    BTW, these posts are terribly interesting, imho. Please keep these up. It’s rare for me to see something that’s both related to anime and my line of work. ^___^

  3. koneko-chan says:

    @Ryan A: Glad to be of some help.

    @meganeshounen: Yeah. I forgot about that one. That would work too. It can be something like increasing a process’ weighting/rank when it gets denied a resource slot. Then in the next decision, the process with the higher weight has a better chance of being selected. I knew I forgot something from OS class.

    Again, I would love to write more about this kind of stuff but it takes alot of time to setup and analyze. Also, I need to be thrown a few ideas every once in awhile. This post was spawned by the happenings at my work/project which made things much easier to write. I’ll see what I can do for the next one.

  4. action says:

    My developer is trying to convince me to move to .
    net from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using Movable-type on a variety of websites
    for about a year and am nervous about switching to another platform.
    I have heard excellent things about
    Is there a way I can import all my wordpress content into it?
    Any help would be greatly appreciated!

  5. Karin says:

    Wow that was strange. I just wrote an really long comment but after I clicked submit my comment
    didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say superb blog!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: