mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
unsafe: tag with unsafe{} some more pointer manipulations
This commit is contained in:
@ -24,7 +24,9 @@ fn test_autolocked_array() {
|
||||
for {
|
||||
mut finished_threads := 0
|
||||
rlock abc {
|
||||
finished_threads = abc[0]
|
||||
finished_threads = unsafe {
|
||||
abc[0]
|
||||
}
|
||||
}
|
||||
if finished_threads == 2 {
|
||||
break
|
||||
|
@ -17,14 +17,16 @@ fn test_autolocked_array_2() {
|
||||
go inc_elements(shared abc, 1, sem)
|
||||
go inc_elements(shared abc, 2, sem)
|
||||
for _ in 0 .. iterations_per_thread2 {
|
||||
abc[2]++
|
||||
unsafe {
|
||||
abc[2]++
|
||||
}
|
||||
}
|
||||
// wait for the 2 coroutines to finish using the semaphore
|
||||
for _ in 0 .. 2 {
|
||||
sem.wait()
|
||||
}
|
||||
rlock abc {
|
||||
assert abc[1] == iterations_per_thread2
|
||||
assert abc[2] == 2 * iterations_per_thread2
|
||||
assert unsafe { abc[1] } == iterations_per_thread2
|
||||
assert unsafe { abc[2] } == 2 * iterations_per_thread2
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn test_semaphore() {
|
||||
sem := sync.new_semaphore()
|
||||
go run_forever(shared abc, sem)
|
||||
for _ in 0 .. 1000 {
|
||||
abc[0]--
|
||||
unsafe { abc[0]-- }
|
||||
}
|
||||
// wait for the 2 coroutines to finish using the semaphore
|
||||
stopwatch := time.new_stopwatch({})
|
||||
|
@ -20,14 +20,19 @@ fn test_shared_array() {
|
||||
go incr(shared foo, 1)
|
||||
for _ in 0 .. 50000 {
|
||||
lock foo {
|
||||
foo[0] -= 2
|
||||
foo[1] += 3
|
||||
unsafe {
|
||||
foo[0] -= 2
|
||||
foo[1] += 3
|
||||
}
|
||||
}
|
||||
}
|
||||
mut finished_threads := 0
|
||||
for {
|
||||
rlock foo {
|
||||
finished_threads = foo[2]
|
||||
finished_threads = unsafe {
|
||||
foo[2]
|
||||
}
|
||||
|
||||
}
|
||||
if finished_threads == 4 {
|
||||
break
|
||||
@ -35,7 +40,15 @@ fn test_shared_array() {
|
||||
time.sleep_ms(100)
|
||||
}
|
||||
rlock foo {
|
||||
assert foo[0] == 100010
|
||||
assert foo[1] == 350020
|
||||
f0 := unsafe {
|
||||
foo[0]
|
||||
}
|
||||
|
||||
f1 := unsafe {
|
||||
foo[1]
|
||||
}
|
||||
|
||||
assert f0 == 100010
|
||||
assert f1 == 350020
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user