[英]What happens under the hood when I call a Rust dylib from native C code?
Say, I have some dummy library written in Rust: 说,我有一些用Rust编写的虚拟库:
#![crate_type = "dylib"]
#[no_mangle]
pub extern "C" fn foo() {
println!("bork!");
}
And I'm using it from C native code like that: 而我正在使用C本机代码:
void foo();
int main()
{
foo();
return 0;
}
I'm particularly interested in two things: 我对两件事特别感兴趣:
Does additional threads gets spawned on the Rust function call? 是否会在Rust函数调用中生成其他线程?
How much blocking happen on such call - mutexes, locks, memory allocations on heap, anything like that. 在这样的调用上发生了多少阻塞 - 互斥锁,锁,堆上的内存分配,类似的东西。
I'm thinking of using Rust for real-time DSP applications and therefore I must be aware of any blocking operations that take place here. 我正在考虑将Rust用于实时DSP应用程序,因此我必须知道这里发生的任何阻塞操作。 But I'm not enough hardcore to dig in actual C-Rust interop implementation myself..
但是我不够自己在实际的C-Rust互操作实现中挖掘...
Nothing special happens. 什么都不会发生。 Compiled Rust code that is exported with
extern C
looks just the same as any other native code. 使用
extern C
导出的编译的Rust代码看起来与任何其他本机代码相同。
Does additional threads gets spawned on the Rust function call?
是否会在Rust函数调用中生成其他线程?
No threads are created, unless your code creates them. 除非您的代码创建线程,否则不会创建任何线程。
How much blocking happen on such call - mutexes, locks, memory allocations on heap, anything like that.
在这样的调用上发生了多少阻塞 - 互斥锁,锁,堆上的内存分配,类似的东西。
No, unless your code does such. 不,除非你的代码这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.