Advertisement
Guest User

Untitled

a guest
May 6th, 2014
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.47 KB | None | 0 0
  1. #!/usr/bin/gorun
  2.  
  3. package main
  4.  
  5. import (
  6.     "fmt"
  7.     "runtime"
  8.     "sync"
  9. )
  10.  
  11. var summ uint64
  12. var wg sync.WaitGroup
  13.  
  14.  
  15. func summator() {
  16.     defer wg.Done()
  17.     for i := uint64(0); i < 100000; i++ {
  18.         summ = summ + 1
  19.     }
  20. }
  21.  
  22. func main() {
  23.     wg.Add(100000)
  24.     for i := uint64(0); i < 100000; i++ {
  25.         go summator()
  26.     }
  27.     wg.Wait()
  28.     fmt.Printf("summ == %d\n", summ)
  29. }
  30.  
  31. func init() {
  32.     runtime.GOMAXPROCS(runtime.NumCPU())
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement