简体   繁体   English

当我从本地C代码调用Rust dylib时会发生什么?

[英]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.

相关问题 当您将字符串传递给 C 中的函数时,幕后会发生什么 - What happens under the hood when you pass a string to a function in C 我可以从 Rust 代码调用 C 或 C++ 函数吗? - Can I call C or C++ functions from Rust code? 分解shell脚本; 引擎盖下会发生什么? - Breaking down shell scripts; What happens under the hood? 通用 C - 当我调用“struct *s”时会发生什么? - generic C - what happens when I call "struct *s"? 在Unix中调用fork()时会发生什么? - What Happens When I Call fork() in Unix? 当我从C中的一个分叉的孩子执行exec()时会发生什么 - what happens when I exec() from a forked child in c 当我分配大量的ndarray时,numpy空做什么? - What is numpy empty doing under the hood when I allocate a massive ndarray? 这种连续C内存分配的方法到底是做什么的? - What exactly is this method of contiguous C memory allocation doing under the hood? 在内存中(在后台)创建结构时的操作顺序是什么? - What is the order of operations when creating a struct in memory (under the hood)? 如果我使用JNI从C中的多个线程调用java函数会发生什么? - What happens if I call a java function from multiple threads from C with JNI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM