On Thu, Oct 16, 2014 at 4:55 PM, Alec Matusis <
mat...@gmail.com> wrote:
>
> I tried the race detector: the servers grew to multi-gigabyte size (instead
> of stable 100MB) within 15 minutes, and took the physical machine down.
> During these 15 min, no race conditions were detected. Without race
> detector, memory errors happened within 1-2 minutes.
> I do understand that maps need to be locked during their modifications, but
> I do not quite understand why they need to be locked during reading them, if
> we do not care about consistency..?
Because maps are a complex mutating data structure. During a write
parts of the map, including internal pointers, will be changing.
Reading the map at the same time as a write is mutating it can easily
send the program into invalid memory.
Ian
>> On Thursday, October 16, 2014 4:50:05 PM UTC-7,
k...@golang.org wrote:
>> Run your program with the race detector:
>>
https://golang.org/doc/articles/race_detector.html
>> It will correctly complain that you can't have a concurrent read and write
>> map operation.
>>
>>
>> On Thursday, October 16, 2014 4:44:26 PM UTC-7, Jesse McNelis wrote:
>>>
>>> On Fri, Oct 17, 2014 at 10:33 AM, Alec Matusis <
mat...@gmail.com> wrote:
>>> > the invalid memory error happens about 1000x more rarely. I would like
>>> > to
>>> > understand why such splitting helps, and whether it's possible to only
>>> > use
>>> > write locks, but not read locks and guarantee that there are no memory
>>> > errors?
>>>
>>> No. Maps aren't thread safe, they are a complex data structure that
>>> can't be atomically updated.
>>> You'll need to put locks around all reads and writes if you want to
>>> use them concurrently.
>>>
>>> No values in Go are thread safe, slices, maps, chan values, ints, floats
>>> etc.
>
> --
> 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/d/optout.