Mon Jan 13 16:06:53 CET 2020

More efficient?

Since there is no direct map from channel to tasks, this isn't
particularly efficient.

To make it more efficient:

- When a task suspends, the select structure should be checked against
  the channel->task maps.

- If there is a hit, the task should be removed from all other channel

- If there is no hit, the task should be added to the channel->task
  map for each task.

Changes needed:

- Tasks are no longer just in one list, so lists should be implemented

- Lists can still be stacks.

- Lists:
  - hot, cold (mutually exclusive)
  - channel's read/write list

It seems to become a lot more complex this way, but linear searches
will be eliminated, so it will be more efficient when there are a
large number of tasks.

How much more memory is needed?
Per channel: + a stack of tasks, one for read and one for write
Per task: - link pointer

There is probably a bound on the number of list elements in total, as
a task will be:
- either hot or cold (one cell)
- part of n channel lists, where n is the select count

So the upper bound is the sum of max select count per task.  That is
statically known.

The hot/cold list can be kept the same, as this is only one byte per

This makes the channel list an "accelerator structure".  I.e. it can
be optionally included to trade memory vs. speed.

The pointers can be shrunk to 8 bit if the number of tasks is smaller
or equal to 255, with one value reserved for null.