Skip to content

Instantly share code, notes, and snippets.

@chuckha
Created September 26, 2013 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckha/6719563 to your computer and use it in GitHub Desktop.
Save chuckha/6719563 to your computer and use it in GitHub Desktop.
Code for a blog post
func GenerateAllPics() {
// Set the number of processors Go can use
runtime.GOMAXPROCS(runtime.NumCPU())
// Make all the channels we need
rows := make(chan []string)
throttle := make(chan struct{}, 10)
doneChan := make(chan int)
// Start reading the CSV
go MustReadRowAtATime("data/training.csv", rows)
// Populate the throttle so that the workers can start working
go Populate(throttle)
// The goroutine that spawns workers that write images
go SpawnJobs(rows, doneChan, throttle)
// Block the main thread
for _ = range doneChan {}
fmt.Println("Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment