Open ysbaddaden opened 5 months ago
We might want to specify a status to swapcontext
, at least to set the :dead
status, and/or have a loadcontext
that would merely load a fiber's context (no need to save the context of a dead fiber + won't override the :dead
status).
This in turns means we'd need ExecutionContext.reschedule(Fiber::Status)
or ExecutionContext.???()
to call loadcontext
(how to name that one: exec? replace? abandon? terminate_fiber?). The later would improve control over the dead fiber's stack: we'd know for sure that the current fiber is dead.
Merging both booleans is theoretically a good idea, but it's not easy in practice, as once the fiber is dead, its status musn't change anymore but #swapcontext
will always set the status to suspended, so either we need to update each assembly to check for the state (tedious), or we need a new #loadcontext
that won't touch the current context (also tedious: must duplicate the current assembly).
Perhaps we could only flip a single bit in swapcontext
?
Of course, a flags enum!
It would valuable to know the current status of a Fiber. Implementing this is easy, but we currently have two booleans to reflect a fiber's status:
@alive
to tell whether the fiber is dead or alive;@context.resumable
to tell whether the fiber is running or suspended;It could be interesting to group these into a single variable (enum), and maybe make it an atomic (set once in the target specific context switch assembly) which might be useful for #15.
Note: we could eventually have sub-states in addition to suspended (e.g. sleep or waiting on something: mutex, channel, event-loop, ...). Useful in combination to https://github.com/crystal-lang/perf-tools/pull/18