Is it allowed to call `std:⁠🧵:*` functions in FFI call?

For example, if my Rust code is compiled to cdylib, can I call std::thread::current(), std::thread::park() or unpark() for current thread?
What if thread creator is not Rust, e.g. C++?
What if thread creator is Rust?

Does the behaviour differ between platforms?


std::thread - Rust says the following about thread::current:

The thread::current function is available even for threads not spawned by the APIs of this module.

park should work too looking at its implementation (it's using a private field within a structure returned by thread::current), and I don't see any reason for the implementation to change to not be compatible with threads not spawned by Rust APIs.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.