当我从本机 C 代码调用 Rust dylib 时,底层会发生什么?

What happens under the hood when I call a Rust dylib from native C code?

说,我有一些用 Rust 编写的虚拟库:

#![crate_type = "dylib"]

#[no_mangle]
pub extern "C" fn foo() {
    println!("bork!");
}

我正在像这样从 C 本机代码中使用它:

void foo();
int main()
{
    foo();
    return 0;
}

我对两件事特别感兴趣:

我正在考虑将 Rust 用于实时 DSP 应用程序,因此我必须了解此处发生的任何阻塞操作。但是我自己还不够硬核,无法深入研究实际的 C-Rust 互操作实现..

没有什么特别的事情发生。使用 extern C 导出的已编译 Rust 代码看起来与任何其他本机代码一样。

Does additional threads gets spawned on the Rust function call?

不会创建任何线程,除非您的代码创建它们。

How much blocking happen on such call - mutexes, locks, memory allocations on heap, anything like that.

不,除非您的代码这样做。