package main

import "time"
import "fmt"
import "sync/atomic"

func main() {
   die := make(chan struct{})
   i := int32(0)
   closed := func() {
       select {
       case <-die:
           atomic.AddInt32(&i, 1)
       default:
           close(die)
           fmt.Println("closed")
       }
   }
   N := 100000
   for i := 0; i < N; i++ {
       go closed()
   }
   time.Sleep(10 * time.Second)
   fmt.Println(atomic.LoadInt32(&i))
}


the close function is thread safety? how about call `closed` at the same 
time.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to