I'm trying to implement a simple stackful coroutine running on RISC-V to learn Rust and here is my code and cargo config:
Rust Playground
# .cargo/config.toml
[build]
target = "riscv64gc-unknown-linux-musl"
[target.riscv64gc-unknown-linux-musl]
linker = "rust-lld"
rustflags = ["-C", "target-feature=+crt-static"]
When I use debug mode or uncomment the println!
statements in the code, the program runs correctly. But when I compile in release mode and run it on QEMU, the test fails and produces the following output:
TASK 1 STARTING
task: 1 counter: 0
TASK 2 STARTING
task: 2 counter: 0
TASK 3 STARTING
task: 3 counter: 0
task: 2 counter: 1
task: 3 counter: 1
task: 3 counter: 2
All tasks finished!
thread 'main' panicked at src\main.rs:28:5:
assertion `left == right` failed
left: 0
right: 3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Why does this happen?Thank you all in advance.