FAQ
That's what I surmised, although I don't think I could prove that it is
impossible given the language semantics.
A sufficiently smart escape analysis pass (that understood waitgroups,
etc.) might let a program race against locals.
On Wednesday, March 30, 2016 at 1:16:18 PM UTC-7, Keith Randall wrote:

Yeah, I know it is known. It's just a lot easier to write than I thought
it would be.

I don't think you could do this without letting S escape. You can't have
2 goroutines race on something allocated on the stack.

On Wed, Mar 30, 2016 at 9:18 AM, minux <mi...@golang.org <javascript:>>
wrote:

On Wed, Mar 30, 2016 at 12:14 PM, 'Keith Randall' via golang-dev <
golan...@googlegroups.com <javascript:>> wrote:
package main

import "fmt"

type S struct {
a, b, c, d int32
}
type T struct {
a, b int64
}

func castStoT(s *S) *T {
var x interface{}
var stop bool
go func() {
for !stop {
x = s
}
}()
go func() {
for !stop {
x = (*T)(nil)
}
}()
for {
t, ok := x.(*T)
if ok && t != nil {
stop = true
return t
}
}
}

func main() {
s := &S{3, 4, 5, 6}
t := castStoT(s)
fmt.Printf("%x %x\n", t.a, t.b)
}
This is known, please see http://research.swtch.com/gorace.
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
groupgolang-dev @
categoriesgo
postedMar 30, '16 at 4:14p
activeMar 31, '16 at 2:29a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase