We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
看到前面已经有一个关于这个问题的讨论,我还是选择了开了一个新的issue谈谈我的想法。
除了使用加锁的方法,还可以使用channel来实现goroutine调度,这是一个典型的 pingpong的问题,加上一个channel接受完成通知就好。
pingpong
package main import ( "fmt" ) func main() { ping := make(chan struct{}, 1) pong := make(chan struct{}, 1) done := make(chan struct{}) ping <- struct{}{} go func() { for i := 0; i < 10; i++ { <-ping fmt.Print(i) pong <- struct{}{} } }() go func() { for i := 0; i < 10; i++ { <-pong fmt.Printf("%c", 'A'+i) ping <- struct{}{} } done <- struct{}{} }() <-done close(ping) close(pong) }
The text was updated successfully, but these errors were encountered:
对了,上述代码忘了 close(done)
close(done)
Sorry, something went wrong.
No branches or pull requests
看到前面已经有一个关于这个问题的讨论,我还是选择了开了一个新的issue谈谈我的想法。
除了使用加锁的方法,还可以使用channel来实现goroutine调度,这是一个典型的
pingpong
的问题,加上一个channel接受完成通知就好。The text was updated successfully, but these errors were encountered: