1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: replace go with spawn

This commit is contained in:
Alexander Medvednikov
2022-11-05 10:46:40 +03:00
parent a082328e40
commit e81e0ac708
126 changed files with 262 additions and 262 deletions

View File

@@ -38,7 +38,7 @@ fn main() {
mut no := nobj
for i in 0 .. nrec {
n := no / (nrec - i)
go do_rec(ch, resch, n)
spawn do_rec(ch, resch, n)
no -= n
}
$if debug {
@@ -49,7 +49,7 @@ fn main() {
n := no / (nsend - i)
end := no
no -= n
go do_send(ch, no, end)
spawn do_send(ch, no, end)
}
assert no == 0
mut sum := i64(0)

View File

@@ -117,11 +117,11 @@ fn main() {
}
ctx.pops_wg.add(n_readers)
for i := 0; i < n_readers; i++ {
go do_rec(ch, i, mut ctx)
spawn do_rec(ch, i, mut ctx)
}
ctx.pushes_wg.add(n_writers)
for i := 0; i < n_writers; i++ {
go do_send(ch, i, mut ctx)
spawn do_send(ch, i, mut ctx)
}
ctx.pushes_wg.wait()
eprintln('>> all pushes done')

View File

@@ -10,7 +10,7 @@ fn do_send(ch chan int) {
fn test_channel_buffered() {
ch := chan int{cap: 1000}
go do_send(ch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. num_iterations {
sum += <-ch

View File

@@ -10,7 +10,7 @@ fn do_send(ch chan int) {
fn test_channel_unbuffered() {
ch := chan int{}
go do_send(ch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. num_iterations {
sum += <-ch

View File

@@ -16,14 +16,14 @@ fn do_send(ch chan int) {
fn test_channel_multi_unbuffered() {
ch := chan int{}
resch := chan i64{}
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_send(ch)
go do_send(ch)
go do_send(ch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_send(ch)
spawn do_send(ch)
spawn do_send(ch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. 4 {
sum += <-resch

View File

@@ -16,14 +16,14 @@ fn do_send(ch chan int) {
fn test_channel_multi_buffered() {
ch := chan int{cap: 100}
resch := chan i64{}
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_send(ch)
go do_send(ch)
go do_send(ch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_send(ch)
spawn do_send(ch)
spawn do_send(ch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. 4 {
sum += <-resch

View File

@@ -22,7 +22,7 @@ fn do_rec_calc_send(chs []chan mut St) {
fn test_channel_array_mut() {
mut chs := [chan mut St{cap: 1}, chan mut St{}]
go do_rec_calc_send(chs)
spawn do_rec_calc_send(chs)
mut t := &St{
n: 100
}

View File

@@ -23,11 +23,11 @@ fn do_send(ch chan int) {
fn test_channel_close_buffered_multi() {
ch := chan int{cap: 10}
resch := chan i64{}
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. 4 {
sum += <-resch
@@ -38,11 +38,11 @@ fn test_channel_close_buffered_multi() {
fn test_channel_close_unbuffered_multi() {
ch := chan int{}
resch := chan i64{}
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_rec(ch, resch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_rec(ch, resch)
spawn do_send(ch)
mut sum := i64(0)
for _ in 0 .. 4 {
sum += <-resch
@@ -53,8 +53,8 @@ fn test_channel_close_unbuffered_multi() {
fn test_channel_close_buffered() {
ch := chan int{cap: 100}
resch := chan i64{}
go do_rec(ch, resch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_send(ch)
mut sum := i64(0)
sum += <-resch
assert sum == i64(8000) * (8000 - 1) / 2
@@ -63,8 +63,8 @@ fn test_channel_close_buffered() {
fn test_channel_close_unbuffered() {
ch := chan int{}
resch := chan i64{cap: 100}
go do_rec(ch, resch)
go do_send(ch)
spawn do_rec(ch, resch)
spawn do_send(ch)
mut sum := i64(0)
sum += <-resch
assert sum == i64(8000) * (8000 - 1) / 2
@@ -72,7 +72,7 @@ fn test_channel_close_unbuffered() {
fn test_channel_send_close_buffered() {
ch := chan int{cap: 1}
t := go fn (ch chan int) {
t := spawn fn (ch chan int) {
ch <- 31
mut x := 45
ch <- 17 or { x = -133 }
@@ -90,7 +90,7 @@ fn test_channel_send_close_buffered() {
fn test_channel_send_close_unbuffered() {
time.sleep(1 * time.second)
ch := chan int{}
t := go fn (ch chan int) {
t := spawn fn (ch chan int) {
mut x := 31
ch <- 177 or { x = -71 }

View File

@@ -15,7 +15,7 @@ fn do_send(ch chan int, mut fin sync.Semaphore) {
fn test_channel_len_cap() {
ch := chan int{cap: queue_len}
mut sem := sync.new_semaphore()
go do_send(ch, mut sem)
spawn do_send(ch, mut sem)
sem.wait()
assert ch.cap == queue_len
assert ch.len == queue_fill

View File

@@ -27,7 +27,7 @@ fn do_rec_calc_send(chs []chan i64, mut sem sync.Semaphore) {
fn test_channel_array_mut() {
mut chs := [chan i64{}, chan i64{cap: 10}]
mut sem := sync.new_semaphore()
go do_rec_calc_send(chs, mut sem)
spawn do_rec_calc_send(chs, mut sem)
mut t := i64(100)
for _ in 0 .. num_iterations {
chs[0] <- t

View File

@@ -36,13 +36,13 @@ fn test_channel_polling() {
ch := chan int{cap: buflen}
resch := chan i64{}
for _ in 0 .. nrec {
go do_rec(ch, resch, objs_per_thread)
spawn do_rec(ch, resch, objs_per_thread)
}
mut n := nobj
for _ in 0 .. nsend {
end := n
n -= objs_per_thread
go do_send(ch, n, end)
spawn do_send(ch, n, end)
}
mut sum := i64(0)
for _ in 0 .. nrec {

View File

@@ -11,7 +11,7 @@ fn f(ch chan int) {
fn test_push_or_unbuffered() {
ch := chan int{}
go f(ch)
spawn f(ch)
mut j := 0
for {
ch <- j or { break }
@@ -23,7 +23,7 @@ fn test_push_or_unbuffered() {
fn test_push_or_buffered() {
ch := chan int{cap: c}
go f(ch)
spawn f(ch)
mut j := 0
for {
ch <- j or { break }
@@ -50,9 +50,9 @@ fn g(ch chan int, res chan int) {
fn test_many_senders() {
ch := chan int{}
res := chan int{}
go g(ch, res)
go g(ch, res)
go g(ch, res)
spawn g(ch, res)
spawn g(ch, res)
spawn g(ch, res)
mut k := 0
for _ in 0 .. 3 * n {
k = <-ch

View File

@@ -16,7 +16,7 @@ fn do_send(ch chan f64, val f64) ?f64 {
fn test_push_propargate() {
ch := chan f64{}
go f(ch)
spawn f(ch)
mut s := 1.0
for {
s = do_send(ch, s) or { break }

View File

@@ -31,10 +31,10 @@ fn test_select() {
chl := chan i64{cap: 1}
chb := chan u8{cap: 10}
recch := chan i64{cap: 0}
go do_rec_i64(recch)
go do_send_int(chi)
go do_send_u8(chb)
go do_send_i64(chl)
spawn do_rec_i64(recch)
spawn do_send_int(chi)
spawn do_send_u8(chb)
spawn do_send_i64(chl)
mut sum := i64(0)
mut rl := i64(0)
mut sl := i64(0)

View File

@@ -79,7 +79,7 @@ fn test_select_blocks() {
}
assert r == true
assert t == true
go f2(ch2, ch3, mut sem)
spawn f2(ch2, ch3, mut sem)
n := <-ch3
assert n == 23
ch2 <- St{
@@ -87,7 +87,7 @@ fn test_select_blocks() {
}
sem.wait()
stopwatch := time.new_stopwatch()
go f1(ch1, ch2, ch3, ch4, ch5, mut sem)
spawn f1(ch1, ch2, ch3, ch4, ch5, mut sem)
sem.wait()
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers

View File

@@ -16,8 +16,8 @@ fn test_select() {
chi := chan int{cap: 10}
recch := chan i64{cap: 10}
chsum := chan i64{}
go do_rec_i64(recch, chsum)
go do_send_int(chi)
spawn do_rec_i64(recch, chsum)
spawn do_send_int(chi)
mut sum := i64(0)
mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap {

View File

@@ -28,12 +28,12 @@ fn test_select() {
chi := chan int{cap: 10}
recch := chan i64{cap: 10}
chsum := chan i64{}
go do_rec_i64(recch, chsum)
go do_rec_i64(recch, chsum)
go do_rec_i64(recch, chsum)
go do_send_int(chi)
go do_send_int2(chi)
go do_send_int3(chi)
spawn do_rec_i64(recch, chsum)
spawn do_rec_i64(recch, chsum)
spawn do_rec_i64(recch, chsum)
spawn do_send_int(chi)
spawn do_send_int2(chi)
spawn do_send_int3(chi)
mut sum := i64(0)
mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap {

View File

@@ -51,15 +51,15 @@ fn test_select() {
chsum2 := chan i64{}
chsumf1 := chan f64{}
chsumf2 := chan f64{}
go do_send_int(ch1, 3)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
go do_rec_f64(chf1, chsumf1)
go do_rec_f64(chf2, chsumf2)
go do_rec_f64(chf2, chsumf2)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
go do_send_int(ch2, 7)
go do_send_int(ch2, 17)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
spawn do_send_int(ch1, 3)
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
spawn do_rec_f64(chf1, chsumf1)
spawn do_rec_f64(chf2, chsumf2)
spawn do_rec_f64(chf2, chsumf2)
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
spawn do_send_int(ch2, 7)
spawn do_send_int(ch2, 17)
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
sum1 := <-chsum1 + <-chsum1 + <-chsum1
sum2 := <-chsum2 + <-chsum2 + <-chsum2

View File

@@ -53,10 +53,10 @@ fn test_select() {
mut chl := new_channel<i64>(1)
mut chb := new_channel<u8>(10)
mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch)
go do_send_int(mut chi)
go do_send_u8(mut chb)
go do_send_i64(mut chl)
spawn do_rec_i64(mut recch)
spawn do_send_int(mut chi)
spawn do_send_u8(mut chb)
spawn do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb]
directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0)

View File

@@ -24,7 +24,7 @@ fn test_many_times_once() {
// It is executed 10 times, but only once actually.
for i := 0; i < n; i++ {
go run(mut m, mut co, c)
spawn run(mut m, mut co, c)
}
for i := 0; i < n; i++ {
<-c
@@ -40,7 +40,7 @@ fn test_many_times_fifth() {
// It is executed 10 times, but only 5 times actually.
for i := 0; i < n; i++ {
go run(mut m, mut co, c)
spawn run(mut m, mut co, c)
}
for i := 0; i < n; i++ {
<-c

View File

@@ -24,7 +24,7 @@ fn test_once() {
// It is executed 10 times, but only once actually.
for i := 0; i < n; i++ {
go run(mut once, mut o, c)
spawn run(mut once, mut o, c)
}
for i := 0; i < n; i++ {
<-c

View File

@@ -29,7 +29,7 @@ fn test_once() {
// It is executed 10 times, but only once actually.
for i := 0; i < n; i++ {
go run(mut once, mut o, c)
spawn run(mut once, mut o, c)
}
for i := 0; i < n; i++ {
<-c

View File

@@ -89,7 +89,7 @@ pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {
pool.waitgroup.add(njobs)
for i := 0; i < njobs; i++ {
if njobs > 1 {
go process_in_thread(mut pool, i)
spawn process_in_thread(mut pool, i)
} else {
// do not run concurrently, just use the same thread:
process_in_thread(mut pool, i)

View File

@@ -44,10 +44,10 @@ fn test_select() {
mut chl := new_channel<i64>(1)
mut chb := new_channel<u8>(10)
mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch)
go do_send_int(mut chi)
go do_send_u8(mut chb)
go do_send_i64(mut chl)
spawn do_rec_i64(mut recch)
spawn do_send_int(mut chi)
spawn do_send_u8(mut chb)
spawn do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb]
directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0)

View File

@@ -15,7 +15,7 @@ fn test_count_10_times_1_cycle_should_result_10_cycles_with_sync() {
mut counter := &Counter{}
wg.add(10)
for i := 0; i < 10; i++ {
go count_one_cycle(mut counter, mut wg)
spawn count_one_cycle(mut counter, mut wg)
}
wg.wait()
assert counter.counter == u64(desired_iterations)
@@ -29,7 +29,7 @@ fn test_count_10_times_1_cycle_should_not_be_10_cycles_without_sync() {
mut counter := &Counter{}
wg.add(10)
for i := 0; i < 10; i++ {
go count_one_cycle_without_sync(mut counter, mut wg)
spawn count_one_cycle_without_sync(mut counter, mut wg)
}
wg.wait()
// Note: we do not assert here, just print, because sometimes by chance counter.counter may be == desired_iterations

View File

@@ -8,7 +8,7 @@ fn f(st Abc) {
fn test_chan_init() {
st := Abc{}
go f(st)
spawn f(st)
i := <-st.ch
assert i == 47
}

View File

@@ -9,8 +9,8 @@ fn simple_thread() u64 {
fn test_sync_thread_id() {
mtid := sync.thread_id()
eprintln('main thread_id: $sync.thread_id().hex()')
x := go simple_thread()
y := go simple_thread()
x := spawn simple_thread()
y := spawn simple_thread()
xtid := x.wait()
ytid := y.wait()
eprintln('main thread_id: $sync.thread_id().hex()')

View File

@@ -10,7 +10,7 @@ fn test_waitgroup_reuse() {
wg.add(1)
mut executed := false
go fn (mut wg WaitGroup, executed voidptr) {
spawn fn (mut wg WaitGroup, executed voidptr) {
defer {
wg.done()
}
@@ -28,7 +28,7 @@ fn test_waitgroup_reuse() {
fn test_waitgroup_no_use() {
mut done := false
go fn (done voidptr) {
spawn fn (done voidptr) {
time.sleep(1 * time.second)
if *(&bool(done)) == false {
panic('test_waitgroup_no_use did not complete in time')