0
即時編寫算法將圖片分解成段並對其進行處理,但是目前使用Go例程的方式並不十分理想。如何在工作池中發送GO例程
我想將其拆分成一個工作池,解僱例行程序並讓每個工作人員重新開始工作,直到完成映像。
我把它分成8例如:
var bounds = img.Bounds()
var halfHeight = bounds.Max.Y/2
var eighthOne = halfHeight/4
var eighthTwo = eighthOne + eighthOne
var eighthThree = eighthOne + eighthTwo
var eighthFive = halfHeight + eighthOne
var eighthSix = halfHeight + eighthTwo
var eighthSeven = halfHeight + eighthThree
elapsed := time.Now()
go Threshold(pic, c2, 0, eighthOne)
go Threshold(pic, c5, eighthOne, eighthTwo)
go Threshold(pic, c6, eighthTwo, eighthThree)
go Threshold(pic, c7, eighthThree, halfHeight)
go Threshold(pic, c8, halfHeight, eighthFive)
go Threshold(pic, c9, eighthFive, eighthSix)
go Threshold(pic, c10, eighthSix, eighthSeven)
go Threshold(pic, c11, eighthSeven, bounds.Max.Y)
從中我再斷火轉到例程此起彼伏,如何優化到這個工人的系統?
感謝
參見[?這是圍棋的習慣工作者線程池(http://stackoverflow.com/questions/38170852/is-this-an-idiomatic-worker -thread-pool-in-go/38172204#38172204) – icza
答案肯定是緩衝的渠道。如果你還沒有經歷它,那麼去巡視就會很好地解釋併發原語。 https://tour.golang.org/concurrency/2 – Gant