We hope Go programming style will encourage people to try
higher-level techniques. In particular, consider structuring your
program so that only one goroutine at a time is ever responsible
for a particular piece of data.
http://golang.org/doc/go_lang_faq.html#atomic_maps
After long discussion it was decided that the typical use of maps
did not require safe access from multiple threads, and in those
cases where it did, the map was probably part of some larger data
structure or computation that was already synchronized.
Therefore requiring that all map operations grab a mutex would
slow down most programs and add safety to few.
---
I think the map situation applies to the case for "protected objects"
(aka Java synchronized) too. Making individual data structures
atomic is only useful when those data structures are the only thing
in the program. More commonly, higher level code combining them
wants to ensure invariants across data structures, in which case
the higher-level coordination makes lower-level mutexes redundant.
Russ
After long discussion it was decided that the typical use of maps
did not require safe access from multiple threads, and in those
cases where it did, the map was probably part of some larger data
structure or computation that was already synchronized.
Therefore requiring that all map operations grab a mutex would
slow down most programs and add safety to few.
>
>
> On Fri, May 28, 2010 at 12:38 PM, Russ Cox <r...@golang.org> wrote:
> After long discussion it was decided that the typical use of maps
> did not require safe access from multiple threads, and in those
> cases where it did, the map was probably part of some larger data
> structure or computation that was already synchronized.
> Therefore requiring that all map operations grab a mutex would
> slow down most programs and add safety to few.
>
> I've been meaning to ask: I'm making the assumption that it's OK to have multiple concurrent readers of a map if no one will be writing to it. Is this a safe assumption?
Yes
-rob
Envoyé de mon iPhone
Can you elaborate? I haven't done any Ada programming,
so I searched the web and found these descriptions of
protected objects:
http://www.iuma.ulpgc.es/users/jmiranda/gnat-rts/node25.htm
http://en.wikibooks.org/wiki/Ada_Programming/Tasking#Protected_types
http://www.adaic.org/docs/95style/html/sec_6/6-1-1.html
and I don't see anything about asynchronous communication there.
Russ
Russ