亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有等待組和無緩沖通道的競爭條件

具有等待組和無緩沖通道的競爭條件

Go
嗶嗶one 2023-05-15 14:58:35
在這篇文章Understanding golang channels: deadlock中得到了我最初問題的(正確的)解決方案之后,我想出了一個稍微不同的解決方案(在我看來讀起來更好:// Binary histogram counts the occurences of each word.package mainimport (    "fmt"    "strings"    "sync")var data = []string{    "The yellow fish swims slowly in the water",    "The brown dog barks loudly after a drink ...",    "The dark bird bird of prey lands on a small ...",}func main() {    histogram := make(map[string]int)    words := make(chan string)    var wg sync.WaitGroup    for _, line := range data {        wg.Add(1)        go func(l string) {            for _, w := range strings.Split(l, " ") {                words <- w            }            wg.Done()        }(line)    }    go func() {        for w := range words {            histogram[w]++        }    }()    wg.Wait()    close(words)    fmt.Println(histogram)}它確實有效,但不幸的是在比賽中運行它,它顯示了 2 個比賽條件:==================WARNING: DATA RACERead at 0x00c420082180 by main goroutine:...Previous write at 0x00c420082180 by goroutine 9:...Goroutine 9 (running) created at:  main.main()你能幫我了解比賽條件在哪里嗎?
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號