v2 / vlib / v / tests / concurrency / shared_struct_method_call_test.v
26 lines · 23 sloc · 326 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Aa {
2mut:
3 b []int
4}
5
6fn append_ok(shared a Aa, new_b int) {
7 lock a {
8 a.b << new_b
9 }
10}
11
12fn (shared a Aa) append_fails(new_b int) {
13 lock a {
14 a.b << new_b
15 }
16}
17
18fn test_shared_struct_method_call() {
19 shared a := Aa{}
20 append_ok(shared a, 1)
21 a.append_fails(2)
22 rlock a {
23 println(a.b)
24 assert a.b == [1, 2]
25 }
26}
27