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

2 coroutine comunicate with 2 channel aborted #16

Open
TirpitzS opened this issue Jan 13, 2020 · 2 comments
Open

2 coroutine comunicate with 2 channel aborted #16

TirpitzS opened this issue Jan 13, 2020 · 2 comments

Comments

@TirpitzS
Copy link

when i use two channel for comunication, call push, it will aborted because of ordinator.current === 0

@TirpitzS
Copy link
Author

consider code like this:

class A
{
void MainLoop();
private:
coroutine::Channel ch1_;
coroutine::Channel ch2_;
};

void A::MainLoop()
{
auto f = &{ch2_.push(1);};
auto co1 = coroutine::create(f);
ch1_.consumer(co1);
auto f2 = &{ch2.pop();};
auto co2 = coroutine::create(f2)
ch2_.consumer(co2);
while(1)
{
coroutine::resume(co1);
coroutine::resume(co2);
}
}

i find that,when i call ch2_.push, it will aborted!I don't know is it a bug or it does not allow using like this.

@tonbit
Copy link
Owner

tonbit commented Apr 12, 2021

Channel design pattern works like:
mainloop call push() to dispatch an object to one channel, and push() will auto resume coroutine of this channel;
this coroutine pop() and handles an object until it yields itself. when no object in channel, pop() will auto yield this coroutine.

In asymmetric coroutine, one routine is not allowed to resume() another coroutine.
resumt() must be called by mainloop of thread.

Since push() will auto resume coroutine of channel, push() is not allowed to be called in coroutine,
it will trigger assert false in code.

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