docs: remove `&` from `shared` initializers (#8499)

pull/8502/head
Uwe Krüger 2021-02-01 21:43:45 +01:00 committed by GitHub
parent 51f2eb81f4
commit 8bf3fe5d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -2655,7 +2655,7 @@ fn (shared b St) g() {
} }
fn main() { fn main() {
shared a := &St{ // create as reference so it's on the heap shared a := St{
x: 10 x: 10
} }
go a.g() go a.g()
@ -2665,6 +2665,7 @@ fn main() {
} }
} }
``` ```
Shared variables must be structs, arrays or maps.
## Decoding JSON ## Decoding JSON

View File

@ -131,12 +131,12 @@ fn i(atomic x u64) {...}
a := St{...} a := St{...}
f(a) f(a)
mut b := &St{...} // reference since transferred to coroutine mut b := St{...}
f(b) f(b)
go g(mut b) go g(mut b)
// `b` should not be accessed here any more // `b` should not be accessed here any more
shared c := &St{...} shared c := St{...}
h(shared c) h(shared c)
atomic d &u64 atomic d &u64
@ -146,7 +146,7 @@ i(atomic d)
Inside a `lock c {...}` block `c` behaves like a `mut`, Inside a `lock c {...}` block `c` behaves like a `mut`,
inside an `rlock c {...}` block like an immutable: inside an `rlock c {...}` block like an immutable:
```v ignore ```v ignore
shared c := &St{...} shared c := St{...}
lock c { lock c {
g(mut c) g(mut c)
f(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: can be generated automatically for `array`/`map` operations:
```v ignore ```v ignore
shared a []int{...} shared a := []int{cap: 5}
go h2(shared a) go h2(shared a)
a << 3 a << 3
// keep in mind that `h2()` could change `a` between these statements // keep in mind that `h2()` could change `a` between these statements
a << 4 a << 4
x := a[1] // not necessarily `4` x := a[1] // not necessarily `4`
shared b map[string]int shared b := map[string]int{}
go h3(shared b) go h3(shared b)
b['apple'] = 3 b['apple'] = 3
c['plume'] = 7 c['plume'] = 7