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

1.5.1 Goroutine和系统线程 这一章的内容写得有问题 #518

Open
p-moon opened this issue Aug 12, 2020 · 3 comments
Open

1.5.1 Goroutine和系统线程 这一章的内容写得有问题 #518

p-moon opened this issue Aug 12, 2020 · 3 comments

Comments

@p-moon
Copy link

p-moon commented Aug 12, 2020

提示:哪一章节的问题,建议如何修改

携程和线程的区别就在于协程重做了上下文切换,减少了内核态和用户态的交互。

而不是每个系统级的线程都会有一个固定大小的栈,一个进程中所有的线程和携程的堆栈空间都是共享的。

@p-moon p-moon closed this as completed Aug 25, 2020
@p-moon p-moon reopened this Aug 25, 2020
@cch123
Copy link
Collaborator

cch123 commented Sep 8, 2020

协程的栈和传统的线程栈都不是一回事的呀

@p-moon
Copy link
Author

p-moon commented Sep 10, 2020

那只要你开辟或者复制内存了,性能就绝对不会高 @cch123 ,而且携程的栈指的应该是函数栈,堆也是,存的都是类似的局部变量。协程和线程最大的区别就在于上下文切换上做了优化,如果还需要开辟额外的空间,那么大概率不会比线程快的

@chai2010
Copy link
Owner

Goroutine和线程的本质区别:Go编译器认识Goroutine的Go语法,可以开很多优化后门;而OS不认识写线程的编程语言,只能采用保守策略。

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