vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.52k stars 2.15k forks source link

live programs hang if a [live] function calls another [live] function #15412

Open jrfondren opened 1 year ago

jrfondren commented 1 year ago

V version: V 0.3.0 b01f71d.fd83b95 OS: 64-bit linux and macos

What did you do?

The following program and variations of it (non-live main calling live f calling live g; no loop or time.sleep):

import time

[live]
fn main() {
    for {
        f()
        time.sleep(500 * time.millisecond)
    }
}

[live]
fn f() {
    println('f()')
}

What did you expect to see?

f()
f()
f()
...

What did you see instead?

No program output. strace only showed thread activity. attaching gdb showed one "livetest" in futex_wait, some gc threads, and another "livetest" thread apparently running without issue from v/vlib/v/live/executable/reloader.v

Remove either [live] and the program works as expected. You can also observe a 97% cpu busywait if the following program is run without -live, and 0% cpu use with -live:

[live]
fn main() {
    mut n := 0
    for {
        f(mut &n)
    }
}

[live]
fn f(mut n &int) {
    n++
}
Lathanao commented 1 year ago

I have the expected result with V 0.3.0 0133ff2

image

jrfondren commented 1 year ago

I have the expected result with V 0.3.0 0133ff2

You're not running it with -live