aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/go-maps-in-action.article4
1 files changed, 1 insertions, 3 deletions
diff --git a/content/go-maps-in-action.article b/content/go-maps-in-action.article
index 7cca838..cc6d62c 100644
--- a/content/go-maps-in-action.article
+++ b/content/go-maps-in-action.article
@@ -156,7 +156,7 @@ This statement declares a `counter` variable that is an anonymous struct contain
To read from the counter, take the read lock:
-
+
counter.RLock()
n := counter.m["some_key"]
counter.RUnlock()
@@ -171,8 +171,6 @@ To write to the counter, take the write lock:
* Iteration order
When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next.
-Since the release of Go 1.0, the runtime has randomized map iteration order.
-Programmers had begun to rely on the stable iteration order of early versions of Go, which varied between implementations, leading to portability bugs.
If you require a stable iteration order you must maintain a separate data structure that specifies that order.
This example uses a separate sorted slice of keys to print a `map[int]string` in key order: