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

Interrupting a long-running coroutine and moving it to another os-level thread #9

Closed
dumblob opened this issue Mar 15, 2022 · 2 comments

Comments

@dumblob
Copy link

dumblob commented Mar 15, 2022

Hi, I'm new to minicoro and try to understand its capabilities. The readme states:

The mco_coro object is not thread safe, you should lock each coroutine into a thread.

Does that mean that it's impossible to interrupt a long-running coroutine and move it to a different os-level thread?

@edubart
Copy link
Owner

edubart commented Mar 15, 2022

Does that mean that it's impossible to interrupt a long-running coroutine and move it to a different os-level thread?

That should be possible if you call mco_yield somewhere from the coroutine entry function, that is the only way to interrupt it (from inside it). What I meant there is that you should not call minicoro functions from different OS threads simultaneously (you would need to use a mutex for that).

You can migrate a coroutine to another thread to make a scheduler, just make sure the coroutine lifetime is always present at most one thread simultaneously.

Also you should take lot of care like not trying to resume a coroutine that is already running in another thread, the library will not catch such mistake.

@edubart edubart closed this as completed Mar 17, 2022
@dumblob
Copy link
Author

dumblob commented Mar 18, 2022

Thanks for clarification. As I understand it, we really can not "interrupt" a long-running coroutine from outside and move it to another os-level thread right after interruption.

Anyway, very nice library!

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

No branches or pull requests

2 participants