Ok, I’m a total go fan now. Hopelessly enamored. My application is simple, it’s an embarrassingly parallel operation writing to independent parts of an array.but I’ve never had such a simple “Just Works” experience with any language.

This was my serial code:

	for i := 0; i < mandel.win.W; i++ {
		for j := 0; j < mandel.win.H; j++ {
			k := escape_number(x0+dx*float64(i), y0+dy*float64(j), mandel.Max_iter)
			mandel.img.Set(i, j, color.Gray16{k})
		}
	}

and this is my parallelized version

	wg := sync.WaitGroup{}
	for i := 0; i < mandel.win.W; i++ {
		wg.Add(1)
		go mandel.compute_column(i, x0, y0, dx, dy, &wg)
	}
	wg.Wait()
}

func (mandel *MandelbrotSet) compute_column(i int, x0 float64, y0 float64, dx float64, dy float64, wg *sync.WaitGroup) {
	for j := 0; j < mandel.win.H; j++ {
		k := escape_number(x0+dx*float64(i), y0+dy*float64(j), mandel.Max_iter)
		mandel.img.Set(i, j, color.Gray16{k})
	}
	wg.Done()
}

No messing about with anything. Just a little counter (effectively) that keeps track of how many goroutines have been fired off and lets each goroutine decrement the counter, so to speak.

SOLD!

(Of course, I’m inordinately please beacause my application – Mandelbrot set viewer – was taking ~4-6s to draw a frame before and now is effectively instantaneous, but the objectively I can see how easy it is to write parallel code with go)