diff options
Diffstat (limited to 'go/goroutines.go')
-rw-r--r-- | go/goroutines.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/go/goroutines.go b/go/goroutines.go new file mode 100644 index 0000000..1eb1eb9 --- /dev/null +++ b/go/goroutines.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "time" + "math/rand" +) + +func f(n int) { + for i := 0; i < 10; i++ { + fmt.Println(n, ":", i) + amt := time.Duration(rand.Intn(250)) + time.Sleep(time.Millisecond * amt) + } +} + +func main() { + for i := 0; i < 10; i++ { + go f(i) + } + var input string + fmt.Scanln(&input) +} + |