Mon Jan 13 16:06:53 CET 2020
Since there is no direct map from channel to tasks, this isn't
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.
- Tasks are no longer just in one list, so lists should be implemented
- Lists can still be stacks.
- 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
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.