blob: ad3dcec1a4681a8df4289568f6ebcf2c94238e47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import sync
struct St{
mut:
n int
}
fn f(ch chan &St, mut sem sync.Semaphore) {
w := St{}
ch <- w
mut x := St{}
ch <- x
// the following works
y := &St{}
ch <- y
mut z := &St{}
ch <- z
sem.wait()
println(z)
}
fn main() {
c := chan &St{}
mut sem := sync.new_semaphore()
go f(c, mut sem)
y := <-c
// this should fail
mut z := <-c
z.n = 9
sem.post()
println(y)
println(z)
}
|