[Stackless] Realistic ticking and acting

stackless at kaishaku.org stackless at kaishaku.org
Wed Jul 12 23:47:13 CEST 2006


I have written 7 different proof of concepts for a relatively simple idea.
Each implementation has drawbacks. Today I wrote an 8th which does not use
channels, and I felt much better about it, but it doesn't do what I want.

I feel the control flow is overly obscured and prone to programmer error.
This is primarily the case with channels, but it looks like I need them.
At times I've wondered why channels are not "considered harmful". ;-)

I want to know how I should model the following in stackless:

I have some actors and a timekeeper.

  1. The timekeeper ticks.
  2. On each tick the actors will act.
     They can start new actions or continue actions
     started in previous ticks which are not yet complete.
     They may partake in group actions, such as a fight.
  3. All actors finish their slice of actions for this tick.
  4. Go to step 1.

The actors do not necessarily know what actions they will perform.
They have a queue, but they could be interrupted.

The actors can perform multiple distinct actions simultaneously,
such as walking and talking. All my proof of concepts were improving
until I decided I wanted multiple "simultaneous" actions per tick,
at which point a second layer of channels destroyed the timeline
and I just couldn't work out the flow well enough to fix it.
So far I have stuck with schedule, run, send, and receive.

Consider a and b actors, with a queue of actions to perform:

  a.queue = [
    [(a.walk,3),(a.ponder,3)],
    [(a.sit,)]
  ]

  b.queue = [
    (b.walk,1),(b.attack,a)]
  ]

This is what should happen:

  tick 1
    actor a walks (1/3)
    actor a ponders (1/3)
    actor b walks (1/1)
  
  tick 2
    actor a walks (2/3)
    actor a ponders (2/3)
    actor b attacks a
  
  tick 3
    actor a fights b
    actor b fights a
  
  tick 4
    actor a fights b
    actor b fights a
    actor b dies
  
  tick 5
    actor a walks (3/3)
    actor a ponders (3/3)
  
  tick 6
    actor a sits down

Each technique I've tried so far has something wrong with it. Often I want
to control where a tasklet goes in the scheduler, for example I might solve
some implementations' problems by being able to insert the tasklet not at
the end of the schedule list, but 1 before the end, so the ticker stays in
the right place. These dilemmas and more plague my implementations, unless
the implementation sacrifices a feature.

Does it sound like I should be using stackless for this?

If so, how should it be modelled?

-- 
 kai

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list