Terminating the ThreadTest

I need a clean way to terminate the threadtest. It's a very messy situation, and we need to be able to cleanly stop processing under a variety of conditions.

 

One of the few certainties is that termination must take place during a call to NewDay; this is the only way to properly include all the final activity. We need to determine the appropriateness of termination and act.

 

Let's start with the simplest situation: the last thread has died out and there are no plans in the plans list. Then it's simple: we automatically terminate and nothing gets lost.

 

Next up in complexity is a thread that has stalled on a PlanSlacker. The grace period has timed out, and we give up on the slacker, record it, and wrap up.

 

But now we start getting into the ugly ones. What if we have a verb in the plans list with a long preparation time, so that it remains in the plans list, but the termination algorithm just waits for it? I suppose that in this case we simply must wait for it to time out, because otherwise there will be no way for the storybuilder to test that verb.

 

Next, what about an infinite looping situation? We can terminate that with a comparison of currently planned verbs with verbs that have severe looping problems. There are several approaches: if the loop contents are a high fraction of the event count, we can terminate; if the currently remaining verbs are loopy verbs, we can terminate. I like this latter detector algorithm.

 

Lastly, there's the matter of termination criterion. Currently, I use time as my method, but it makes debugging hell. I shall convert it to an event-based system, using orders of magnitude for simplicity of calculation.