FAQ
In the example http://golang.org/pkg/sync/atomic/#example_Value_readMostly
why are we creating a new copy of map1 in map2 before storing it into Value
again? If the consumers are bound to use only the read and update methods
(by some mechanism), shouldn't we be able to update the same map and store
it back? What are the pitfalls that are being avoided by making a full
copy?


--
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.

Search Discussions

  • Henrik Johansson at Dec 23, 2014 at 12:18 pm
    Because it is already published in that case and updating a map requires
    synchronization which is what the example avoids.
    On Dec 23, 2014 12:42 PM, "Mukund Rajamannar" wrote:

    In the example http://golang.org/pkg/sync/atomic/#example_Value_readMostly
    why are we creating a new copy of map1 in map2 before storing it into Value
    again? If the consumers are bound to use only the read and update methods
    (by some mechanism), shouldn't we be able to update the same map and store
    it back? What are the pitfalls that are being avoided by making a full
    copy?


    --
    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.
    --
    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.
  • Jesse McNelis at Dec 23, 2014 at 12:32 pm

    On 23 Dec 2014 22:42, "Mukund Rajamannar" wrote:
    In the example http://golang.org/pkg/sync/atomic/#example_Value_readMostly
    why are we creating a new copy of map1 in map2 before storing it into Value
    again? If the consumers are bound to use only the read and update methods
    (by some mechanism), shouldn't we be able to update the same map and store
    it back? What are the pitfalls that are being avoided by making a full
    copy?
    >

    You gain not having to lock the mutex on read thus preventing writers from
    blocking readers.

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 23, '14 at 11:42a
activeDec 23, '14 at 12:32p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase