That's interesting. What is the cost of switching the stack when calling C code? Do you allocate a new stack every time a C function is called from Rust?
If you inline a compiled C function, don't you have to do the stack switching for whatever that inlined function might call? Or do you only inline code that doesn't have any function calls?
Re:A turning point for GNU libc
by 0xABADC0DA on Wednesday April 04, 2012 @09:11AM
(#3797351)
Ok I understand that you can switch to a larger stack to call C code, although as I said you can't "just call normal C function directly". You can even discount the cost to acquire it by having it stick with the thread using it (no locking, alloc, etc after the first use).
That might be ok for Rust where many 'tasks' might be computational only and never call a C function. But with Google Go, I think they said "we want to have a million threads each reading a socket" or some other arbitrary limit which isn't possible in 32-bit using system threads (even with segmented stack).
Does Rust do it's own threading, and if so what are the advantages you perceive to doing so?
Note that another cool thing we can do is to statically link clang-compiled C code with Rust code and LLVM can inline your small C functions directly into your Rust functions and save you the stack switch -- this is one of the coolest things we can do with LLVM, IMHO.