aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/sync/array_rlock_test.v
blob: ad4f778b60708c69dd38ceaa7df0e66e5d834757 (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
34
35
36
37
38
fn test_shared_modification() {
	shared foo := &[2, 0, 5]
	lock foo {
		unsafe {
			foo[1] = 3
			foo[0] *= 7
			foo[1]--
			foo[2] -= 2
		}
	}
	rlock foo {
		unsafe {
			assert foo[0] == 14
			assert foo[1] == 2
			assert foo[2] == 3
		}
	}
}

[direct_array_access]
fn test_shared_direct_modification() {
	shared foo := &[2, 0, 5]
	lock foo {
		unsafe {
			foo[1] = 3
			foo[0] *= 7
			foo[1]--
			foo[2] -= 2
		}
	}
	rlock foo {
		unsafe {
			assert foo[0] == 14
			assert foo[1] == 2
			assert foo[2] == 3
		}
	}
}