Skip to content

Instantly share code, notes, and snippets.

@stefantalpalaru
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefantalpalaru/86751a89e06ca3d910ce to your computer and use it in GitHub Desktop.
Save stefantalpalaru/86751a89e06ca3d910ce to your computer and use it in GitHub Desktop.
import golib
proc whisper(left, right: chan[int32]) {.goroutine.} =
left <- 1 + <-right
proc first_whisper(c: chan[int32]) {.goroutine.} =
c <- 1
proc go_main() {.gomain.} =
## a slowdown in this scenario for gccgo-4.9.2 but not for go-1.4.2
# runtime_gomaxprocsfunc(runtime_ncpu)
const n = 500000
var
leftmost = make_chan(int32)
right = leftmost
left = leftmost
for i in 0..(n - 1):
right = make_chan(int32)
go whisper(left, right)
left = right
go first_whisper(right)
echo(<-leftmost)
golib_main()
# not reached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment