v2 / vlib / v / checker / tests / chan_ref.vv
33 lines · 30 sloc · 397 bytes · 0c8ce3bcb9fd4a2e5bd5f991a5a07da976d780d7
Raw
1import sync
2
3struct St {
4mut:
5 n int
6}
7
8fn f(ch chan &St, mut sem sync.Semaphore) {
9 w := St{}
10 ch <- w
11 mut x := St{}
12 ch <- x
13 // the following works
14 y := &St{}
15 ch <- y
16 mut z := &St{}
17 ch <- z
18 sem.wait()
19 println(z)
20}
21
22fn main() {
23 c := chan &St{}
24 mut sem := sync.new_semaphore()
25 go f(c, mut sem)
26 y := <-c
27 // this should fail
28 mut z := <-c
29 z.n = 9
30 sem.post()
31 println(y)
32 println(z)
33}
34