No. Please read golang.org/ref/mem regarding Go memory model.
On Feb 3, 2014 6:58 PM, "Maxim Khitrov" <m...@mxcrypt.com> wrote:
>
> On Mon, Feb 3, 2014 at 5:56 PM, minux <minu...@gmail.com> wrote:
> >
> > On Feb 3, 2014 5:51 PM, <drago....@gmail.com> wrote:
> >>
> >> Hello,
> >> If I have the following code snippet, and the env. GOMAXPROC>1
> >>
> >> func main() {
> >> a:=6
> >> go func() {
> >> b:=a
> >> }()
> >> }
> >>
> >> and presumably the second goroutine is executed on other processor than
> >> the main func, will variable b will always get the value written to a, in
> >> the main func (and no some previous CPU cached value of a). There are no
> >> explicit memory barriers after a assignment.
> > No. Please read golang.org/ref/mem regarding Go memory model.
> Why not? The value of a has to be copied in the main goroutine to
> create the closure, then the value of the copy is assigned to b in the
the new goroutine closes over &a, not a.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No. Please read golang.org/ref/mem regarding Go memory model.
--
--
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.
I don't know the details but I imagine that a closure is created during compilation.
Perhaps I'm misunderstanding what a closure is. I thought a closure in Go was something like:
f, ... := func (...) (...) {
...
}
and I thought that that piece of code was compiled with the rest of program.
Does Go have any JIT capabilities?
--
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...@googlegroups.com.
Nico, thanks a lot for your document. It helped me to shed some light on Go's memory model.I can't understand why http://play.golang.org/p/UeHAShi_dS example of you, exits immediately. Can you explain.If I put one trace line, It runs for 10 secs as I expected it to run: http://play.golang.org/p/S6AJD0HNz0