| 1 | import sync |
| 2 | |
| 3 | struct St { |
| 4 | mut: |
| 5 | n int |
| 6 | } |
| 7 | |
| 8 | fn 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 | |
| 22 | fn 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 |