Created
January 15, 2013 06:54
-
-
Save dojiong/4536745 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func pusher(ch chan string, data string, count int) { | |
for count > 0 { | |
ch <- data | |
count -= 1 | |
} | |
} | |
func puller(ch chan string, end chan int) { | |
count := 0 | |
for { | |
if _, ok := <- ch; !ok { | |
break | |
} | |
count += 1 | |
} | |
end <- count | |
} | |
func main() { | |
data := string(make([]byte, 1024 * 1024 * 1024)) | |
fmt.Println(len(data)) | |
ch := make(chan string) | |
end_ch := make(chan int) | |
go puller(ch, end_ch) | |
go puller(ch, end_ch) | |
go puller(ch, end_ch) | |
go puller(ch, end_ch) | |
pusher(ch, data, 1024) | |
close(ch) | |
for i :=0; i < 4; i++ { | |
n := <- end_ch | |
fmt.Println(n) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment