Go routine after a total of exactly 20 numbers


(Babbu Agrawal) #1

Go routine after a total of exactly 20 numbers


(Johan Dahl) #2

Hi. How much work does each go routine do? Twenty routines printing one number each? 100 routines but stop after 20 numbers are written?


(Johan Dahl) #4

You could have a counter which all go routines increment and a mutex which the go routines locks and unlocks then they increments it and if the counter is 20 should the go routine jus return


(Norbert Melzer) #6

This looks quite obfuscated.

In general, I’d not use the go-routine to print the values, I’d use them to generate them and print them from the main:

https://play.golang.org/p/Y4DqMgqrjzp