FAQ
1. Is it possible that the program will print {1, 4} or {3, 2} ?:
http://play.golang.org/p/nWWcmSyXMO
2. Is it possible that the program will panic ? (Is it true that:
m["1"]="1" HAPPENS-BEFORE m["2"]="2" or m["2"]="2" HAPPENS-BEFORE
m["1"]="1" ?): http://play.golang.org/p/K1-kTz3Kjq

--
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/groups/opt_out.

Search Discussions

  • Dave Cheney at Nov 13, 2013 at 9:06 am

    On Wed, Nov 13, 2013 at 7:53 PM, wrote:
    1. Is it possible that the program will print {1, 4} or {3, 2} ?:
    http://play.golang.org/p/nWWcmSyXMO
    yes, the result is undefined
    2. Is it possible that the program will panic ? (Is it true that: m["1"]="1"
    HAPPENS-BEFORE m["2"]="2" or m["2"]="2" HAPPENS-BEFORE m["1"]="1" ?):
    http://play.golang.org/p/K1-kTz3Kjq
    yes, and it probably will, concurrent map modification is very likely
    to corrupt the internal structures of the Go hashmap type.
    --
    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/groups/opt_out.
    --
    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/groups/opt_out.
  • Michal at Nov 13, 2013 at 9:15 am
    Thanks. How can I get some randomness - I always get {3, 4} and map[1:1
    2:2] ?

    W dniu środa, 13 listopada 2013 10:06:13 UTC+1 użytkownik Dave Cheney
    napisał:
    On Wed, Nov 13, 2013 at 7:53 PM, <mic...@zeto.wroc.pl <javascript:>>
    wrote:
    1. Is it possible that the program will print {1, 4} or {3, 2} ?:
    http://play.golang.org/p/nWWcmSyXMO
    yes, the result is undefined
    2. Is it possible that the program will panic ? (Is it true that:
    m["1"]="1"
    HAPPENS-BEFORE m["2"]="2" or m["2"]="2" HAPPENS-BEFORE m["1"]="1" ?):
    http://play.golang.org/p/K1-kTz3Kjq
    yes, and it probably will, concurrent map modification is very likely
    to corrupt the internal structures of the Go hashmap type.
    --
    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 <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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/groups/opt_out.
  • Dave Cheney at Nov 13, 2013 at 9:37 am
    In the playground, the results are always cached.

    If you want to see this race, use the race detector.

    lucky(~/src) % go run -race race.go
    ==================
    WARNING: DATA RACE
    Write by goroutine 4:
       main.func·002()
           /home/dfc/src/race.go:10 +0x65

    Previous write by goroutine 3:
       main.func·001()
           /home/dfc/src/race.go:9 +0x5f

    Goroutine 4 (running) created at:
       main.main()
           /home/dfc/src/race.go:10 +0x15f

    Goroutine 3 (finished) created at:
       main.main()
           /home/dfc/src/race.go:9 +0xf0
    ==================
    {3 4}
    Found 1 data race(s)
    exit status 66
    lucky(~/src) % cat race.go
    package main

    import "fmt"

    func main() {
             done := make(chan bool)
             type T struct{ a, b string }
             var x T
             go func() { x = T{"1", "2"} }()
             go func() { x = T{"3", "4"}; done <- true }()
             <-done
             fmt.Println(x)
    }
    On Wed, Nov 13, 2013 at 8:15 PM, wrote:
    Thanks. How can I get some randomness - I always get {3, 4} and map[1:1
    2:2] ?

    W dniu środa, 13 listopada 2013 10:06:13 UTC+1 użytkownik Dave Cheney
    napisał:
    On Wed, Nov 13, 2013 at 7:53 PM, wrote:
    1. Is it possible that the program will print {1, 4} or {3, 2} ?:
    http://play.golang.org/p/nWWcmSyXMO
    yes, the result is undefined
    2. Is it possible that the program will panic ? (Is it true that:
    m["1"]="1"
    HAPPENS-BEFORE m["2"]="2" or m["2"]="2" HAPPENS-BEFORE m["1"]="1" ?):
    http://play.golang.org/p/K1-kTz3Kjq
    yes, and it probably will, concurrent map modification is very likely
    to corrupt the internal structures of the Go hashmap type.
    --
    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.
    --
    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/groups/opt_out.
    --
    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/groups/opt_out.
  • Michal at Nov 13, 2013 at 9:40 am
    Many thanks !

    W dniu środa, 13 listopada 2013 10:37:31 UTC+1 użytkownik Dave Cheney
    napisał:
    In the playground, the results are always cached.

    If you want to see this race, use the race detector.

    lucky(~/src) % go run -race race.go
    ==================
    WARNING: DATA RACE
    Write by goroutine 4:
    main.func·002()
    /home/dfc/src/race.go:10 +0x65

    Previous write by goroutine 3:
    main.func·001()
    /home/dfc/src/race.go:9 +0x5f

    Goroutine 4 (running) created at:
    main.main()
    /home/dfc/src/race.go:10 +0x15f

    Goroutine 3 (finished) created at:
    main.main()
    /home/dfc/src/race.go:9 +0xf0
    ==================
    {3 4}
    Found 1 data race(s)
    exit status 66
    lucky(~/src) % cat race.go
    package main

    import "fmt"

    func main() {
    done := make(chan bool)
    type T struct{ a, b string }
    var x T
    go func() { x = T{"1", "2"} }()
    go func() { x = T{"3", "4"}; done <- true }()
    <-done
    fmt.Println(x)
    }

    On Wed, Nov 13, 2013 at 8:15 PM, <mic...@zeto.wroc.pl <javascript:>>
    wrote:
    Thanks. How can I get some randomness - I always get {3, 4} and map[1:1
    2:2] ?

    W dniu środa, 13 listopada 2013 10:06:13 UTC+1 użytkownik Dave Cheney
    napisał:
    On Wed, Nov 13, 2013 at 7:53 PM, wrote:
    1. Is it possible that the program will print {1, 4} or {3, 2} ?:
    http://play.golang.org/p/nWWcmSyXMO
    yes, the result is undefined
    2. Is it possible that the program will panic ? (Is it true that:
    m["1"]="1"
    HAPPENS-BEFORE m["2"]="2" or m["2"]="2" HAPPENS-BEFORE m["1"]="1" ?):
    http://play.golang.org/p/K1-kTz3Kjq
    yes, and it probably will, concurrent map modification is very likely
    to corrupt the internal structures of the Go hashmap type.
    --
    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.
    --
    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 <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 13, '13 at 8:53a
activeNov 13, '13 at 9:40a
posts5
users2
websitegolang.org

2 users in discussion

Michal: 3 posts Dave Cheney: 2 posts

People

Translate

site design / logo © 2022 Grokbase