第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 gooutins 和渠道的并發(fā)受限消費(fèi)者

使用 gooutins 和渠道的并發(fā)受限消費(fèi)者

Go
牛魔王的故事 2021-06-29 13:57:02
我試圖重現(xiàn)“良好管理資源的方法是啟動(dòng)固定數(shù)量的句柄 goroutines,所有這些 goroutines 都從請(qǐng)求通道讀取。” 從Effective Go 中發(fā)現(xiàn)fatal error: all goroutines are asleep - deadlock!這個(gè)想法很簡單:有 1 個(gè)隊(duì)列和 1 個(gè)結(jié)果通道和幾個(gè)有限數(shù)量的“工人”。我的代碼在 Go Playgroundqueue := make(chan *Request)result := make(chan int)quit := make(chan bool)go Serve(queue, quit)for i := 0; i < 10; i++ {    req := Request{i, result}    queue <- &req}close(queue)for i := 0; i < 10; i++ {    fmt.Printf("Finished %d\n", <-result)}fmt.Printf("All finished\n")quit <- true功能服務(wù):func handle(queue chan *Request) {    for r := range queue {        //process(r)        fmt.Printf("Processing %d\n", r.i)        r.r <- r.i    }}func Serve(clientRequests chan *Request, quit chan bool) {    MaxOutstanding := 2    // Start handlers    for i := 0; i < MaxOutstanding; i++ {        go handle(clientRequests)    }    <-quit // Wait to be told to exit.}怎么了?或者可能有更簡單的解決方案來實(shí)現(xiàn)數(shù)量有限的處理請(qǐng)求的工人?
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 198 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)