diff --git a/shadirconcurrent/main.go b/shadirconcurrent/main.go index c304b94..a03894a 100644 --- a/shadirconcurrent/main.go +++ b/shadirconcurrent/main.go @@ -6,10 +6,9 @@ import "io" import "log" import "os" import "path/filepath" -import "sync/atomic" +import "time" var chan_hash chan string -var running int32 func walk(path string, info os.FileInfo, err error) error { if err != nil { @@ -20,7 +19,6 @@ func walk(path string, info os.FileInfo, err error) error { if info.IsDir() { return nil } else { - atomic.AddInt32(&running, 1) go hash(info.Name(), path) } return nil @@ -54,10 +52,12 @@ func main() { if err := filepath.Walk(os.Args[1], walk); err != nil { panic(err) } - for str := range chan_hash { - fmt.Println(str) - atomic.AddInt32(&running, -1) - if running <= 0 { + + for { + select { + case str := <-chan_hash: + fmt.Println(str) + case <-time.After(10 * time.Millisecond): return } }