Closing-channel.go result ?? #101

Open
mudongliang opened this Issue Mar 25, 2015 · 4 comments

4 participants

@mudongliang

This is the result of gobyexample/example/closing-channels/closing-channels.go in your website !
$ go run closing-channels.go
sent job 1
received job 1
sent job 2
received job 2
sent job 3
received job 3
sent all jobs
received all jobs

I want to ask whether the result is always the same , or different at runtime !

@andradei

It would always be the same. Even though there is a part of the code that is run on a separate thread, it runs in sync with the main thread.

@Bruce-sz

I carefully check the code, and the "GitHub" code is the same, but why I always get the following results:
[ go run closechan.go | done: 307.238771ms ]
sent job 1
sent job 2
sent job 3
sent all jobs
received job 1
received job 2
received job 3
received all jobs

@pawanrawal

I think this is because the channel is buffered, hence all jobs are sent first and then received. IMHO , its a bug @mmcgrana

@andradei

Also, sometimes the execution of so little code is "too fast" and the result always comes out in order as though it didn't run on separate threads. But yeah, it could also be a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment