v
v copied to clipboard
The return from thread
E:\code\demo>v doctor
OS: windows, Microsoft Windows 10 רҵ v19042 64 λ
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
CC version: Error: exec failed (CreateProcess) with code 2: 系统找不到指定的文件。
cmd: cc --version
getwd: E:\code\demo
vmodules: C:\Users\Administrator\.vmodules
vroot: E:\v
vexe: E:\v\v.exe
vexe mtime: 2022-08-26 11:59:38
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 ea16319.02a47f4
Git version: git version 2.37.2.windows.2
Git vroot status: weekly.2022.33-86-g02a47f42-dirty (8 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-windows-amd64 125e21e2
import rand
import os
fn main() {
for {
h := go call_test()
h.wait()
//time.sleep(500 * time.millisecond)
}
}
struct Test {
mut:
str string
}
fn test() []string {
mut ret := []string{}
ret << rand.string(rand.int_in_range(10,20) or {15})
return ret
}
fn call_test() {
mut ret := []string{}
mut thread := []thread []string{}
for _ in 0..7 {
thread << go test()
}
thread_ret := thread.wait()
for item in thread_ret {
ret << item
}
if ret.any(it == '') {
println(ret)
}
}
The return value here should be all non-empty strings but.
On my ubuntu pc (
OS: linux, Ubuntu 20.04.4 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
getwd: /home/woody/sources/v/bugs
vmodules: /home/woody/.vmodules
vroot: /home/woody/sources/v/v
vexe: /home/woody/sources/v/v/v
vexe mtime: 2022-08-27 19:39:38
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 d08edf8.d75c62b
Git version: git version 2.25.1
Git vroot status: weekly.2022.34-38-gd75c62b8
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 827f7452
)
your program works as expected, here are no empty strings. The program loops forever and prints no output.
It might be a windows only problem.
Did you execute a v up
?
It seems no problem if use -cc msvc
for item in thread_ret {
ret << item.clone()
}
when i clone the string return from the threads then it is ok. it should be the gc problem in windows.