I have a function in Rust that spawns a thread and called a function to read key from terminal:
use crossterm::event;
#[ocaml::func]
pub fn test_read() -> () {
let (tx, rx) = channel::<Option<event::Event>>();
thread::spawn(move || loop {
let event = event::read().ok();
tx.send(event).unwrap();
});
rx.recv().unwrap();
}
I use ocaml-rs to create a static library from Rust code and then use it in OCaml program using (foreign_archives lib)
dune stanza.
I’m trying to make it work on Windows. When the function is called from OCaml, it panics here in Rust std library. However, when I call this function from Rust program, it works. Calling event::read()
from the main thread in OCaml also works.
Looking at the code that panicked, it looks like it is loading functions from Windows dlls at the init time. So it looks like in OCaml new threads don’t have these functions loaded. I’m noob in system programming, especially on Windows, so I would appreciate any clues of what might cause this problem.