初级会员
  • 第 34719 位会员
  • flyaways
  • 2019-04-16 15:35:44
  • Offline
  • 20 7

最近发布的主题

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • ```go package main import ( "fmt" "sync" ) func main() { wg := &sync.WaitGroup{} wg.Add(2) limit := 26 numChan := make(chan int, 1) charChan := make(chan int, 1) charChan <- 1 go func() { defer wg.Done() for i := 0; i < limit; i++ { <-charChan fmt.Printf("%c\n", 'a'+i) numChan <- 1 } }() go func() { defer wg.Done() for i := 0; i < limit; i++ { <-numChan fmt.Println(i) charChan <- 1 } }() wg.Wait() close(charChan) close(numChan) } ```
  • ```go package main import ( "fmt" "runtime" "sync" ) func main() { var wg sync.WaitGroup wg.Add(2) runtime.GOMAXPROCS(1) limit := 26 //输出字母 go func() { defer wg.Done() for i := 0; i < limit; i++ { fmt.Printf("%c\n", 'a'+i) runtime.Gosched() } }() //输出数字 go func() { defer wg.Done() for i := 0; i < limit; i++ { fmt.Println(i) runtime.Gosched() } }() wg.Wait() } ```