Sat Nov 8 14:12:57 EST 2014

IO state machines

These things are not trivial.  Currently writing one for a gdb stub.
Seems that a lot can be generalized however.  Something can be learned

- stream-oriented protocols
- memory constraints

In general, such a problem is best solved by a coroutine / task
approach, where each independent element in the stream processing is a
separate task.

The problem is "suspending".  Some approaches ordered in increasing
suspend granularity:

- pre-emptive multitasking: suspend at machine level
- cooperative multitasking: suspend at a source-level coherent point
- state machines: suspend

The first two use stacks, the latter one uses explicit suspend points.
Abstacting away suspend points trades in predictability for ease of

When working with explicit suspend (state machines), there is a
trade-off between control complexity and buffer memory usage.
Depending on the kind of protocol, there is usually an upper limit to
the size of a buffer that contains the "largest" protocol element in
such a way that there is no space needed to store detailed
intermediate processing.

Take home argument:
- Split design abstractly into cooperating coroutines
- Add buffering to reduce suspend problems
- Granularity is a trade-off between worst-case processing time,
  memory usage, code complexity due to fsm-ification.