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

期待解决select如何释放等待的channel的 #11

Open
zdyj3170101136 opened this issue Nov 8, 2019 · 1 comment
Open

期待解决select如何释放等待的channel的 #11

zdyj3170101136 opened this issue Nov 8, 2019 · 1 comment

Comments

@zdyj3170101136
Copy link

select的源码中在被唤醒后,会把在其他channel上等待的都删除。

但是这有一个问题,就是channel如何识别这是第一个select,以及如何在唤醒第一个select后其他的channel碰到此select的不会去唤醒他?

详情可看chan源码,我也在解决这个问题,可惜还是有疑惑

@yangxikun
Copy link

当有多个 channel ready时,多个 channel 的等待队列在将 g 出队时,会判断该 g 是否通过 select 入队的,如果是,检查 spg.g.selectDone 是否标记为1了,如果是就会跳过,否则就唤醒,对应的代码是 runtime/chan.go: func (q *waitq) dequeue() *sudog {}

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