Go routine after a total of exactly 20 numbers

Go routine after a total of exactly 20 numbers

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

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

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.