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

一个协程里创建一个协程并co_resume会发会什么后果? #22

Open
wayland-chen opened this issue Mar 8, 2017 · 2 comments

Comments

@wayland-chen
Copy link

例如:
void fun(void *)
{
co_create(&co, null, fun, null);
co_resume(co);
}

int main(int argc, char** argvs)
{
stCoroutinue* co;
co_create(&co, null, fun, null);
co_resume(co);
}

@popstk
Copy link

popstk commented Apr 13, 2017

按标题看不会怎么样,协程可以创建并co_resume另一个协程。
然而给的例子是递归的,会栈溢出而core dumped。
libco是非对称协程,因此你在协程A里面co_resume协程B,就相当于协程A调用协程B,libco会用一个CallStack保存这样调用关系。
这个CallStack长度是只有128,这段代码的fun大概嵌套126次就会core dumped(每个线程首次创建协程都会初始化一个main协程,并且总是在CallStack的栈底)。

@YingshuLu
Copy link

与普通的递归调用一样的结果:栈溢出

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

3 participants