On Sat, Apr 25, 2015 at 1:53 PM, wrote:
My second question might not make sense sorry, i'll try to clarify. Imagine
two goroutines, one created within the other as an anonymous function, both
using a single channel created in the first goroutine, both served by the
same OS thread. Does it now, or is it feasible in the future that the
channel and its values could be allocated on the first goroutines stack?
I probably am missing something fundamental about the go runtime that would
answer it for me (perhaps that there is no guarantee the same OS thread
serves if GOMAXPROCS > 1?) What led me to the thought was whether to pass a
channel back from a function or create it and pass it in instead. If there
are no design decisions about which should control whether its buffered or
not, I thought may be there is a performance difference.
If you could prove that the lifetime of a goroutine exceeded the
lifetime of a buffered channel, then you could conclude that values
sent on the channel did not escape. Using a nested function doesn't
help one way or another. You would have to prove first that the
channel does not escape--that you can observe all uses of the channel.
The channel would have to be used in a for/range statement or
something equivalent--you would have to know for sure when all values
on the channel had been read. You would have to know for sure that
all values were read before the sending function finished, implying
the use another channel or a mutex or something to let the receiver
tell the sender that it was done. You would have to know for sure
that there were no panics anywhere in the sending function--no nil
pointer deferences, no calls to unknown functions that might panic.
I doubt many real programs could pass this analysis. I doubt anybody
would ever bother writing it. If it were written, I doubt it would be
worth adding to the compiler--it would increase compile time for all
programs for the benefit of very few programs.
Ian
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.