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