From 8bf3fe5d48b91c1270d8456050d594387fdb737d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Mon, 1 Feb 2021 21:43:45 +0100 Subject: [PATCH] docs: remove `&` from `shared` initializers (#8499) --- doc/docs.md | 3 ++- doc/upcoming.md | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 17c743ef60..8abdd5833b 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2655,7 +2655,7 @@ fn (shared b St) g() { } fn main() { - shared a := &St{ // create as reference so it's on the heap + shared a := St{ x: 10 } go a.g() @@ -2665,6 +2665,7 @@ fn main() { } } ``` +Shared variables must be structs, arrays or maps. ## Decoding JSON diff --git a/doc/upcoming.md b/doc/upcoming.md index c6970b052f..bab10ce4b3 100644 --- a/doc/upcoming.md +++ b/doc/upcoming.md @@ -131,12 +131,12 @@ fn i(atomic x u64) {...} a := St{...} f(a) -mut b := &St{...} // reference since transferred to coroutine +mut b := St{...} f(b) go g(mut b) // `b` should not be accessed here any more -shared c := &St{...} +shared c := St{...} h(shared c) atomic d &u64 @@ -146,7 +146,7 @@ i(atomic d) Inside a `lock c {...}` block `c` behaves like a `mut`, inside an `rlock c {...}` block like an immutable: ```v ignore -shared c := &St{...} +shared c := St{...} lock c { g(mut c) f(c) @@ -166,14 +166,14 @@ block. However in simple and obvious cases the necessary lock/unlock can be generated automatically for `array`/`map` operations: ```v ignore -shared a []int{...} +shared a := []int{cap: 5} go h2(shared a) a << 3 // keep in mind that `h2()` could change `a` between these statements a << 4 x := a[1] // not necessarily `4` -shared b map[string]int +shared b := map[string]int{} go h3(shared b) b['apple'] = 3 c['plume'] = 7