package main import ( "bufio" "fmt" "os" "runtime" "sync" ) func main() { // set number of threads threads := runtime.NumCPU() runtime.GOMAXPROCS(threads) // main data channel c := make(chan string) // wait group for threads var wg sync.WaitGroup wg.Add(threads) defer wg.Wait() // wait for threads to finish // start worker threads for range threads { go func() { defer wg.Done() for data := range c { fmt.Println(data) } }() } // read data from stdin and pipe to threads scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { text := scanner.Text() c <- text } close(c) }