Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiber#status #16

Open
ysbaddaden opened this issue Jun 20, 2024 · 4 comments
Open

Fiber#status #16

ysbaddaden opened this issue Jun 20, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@ysbaddaden
Copy link
Owner

ysbaddaden commented Jun 20, 2024

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 crystal-lang/perf-tools#18

@ysbaddaden ysbaddaden added the enhancement New feature or request label Jun 20, 2024
@ysbaddaden ysbaddaden self-assigned this Jun 20, 2024
@ysbaddaden
Copy link
Owner Author

ysbaddaden commented Jun 20, 2024

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.

ysbaddaden added a commit that referenced this issue Jun 20, 2024
@ysbaddaden
Copy link
Owner Author

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).

@straight-shoota
Copy link

Perhaps we could only flip a single bit in swapcontext?

@ysbaddaden
Copy link
Owner Author

Of course, a flags enum!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants