I'm writing my own implementation of threads (for fun), and I've decided not to use pthreads. I've been using the libc::clone
wrapper function, but I was concerned about the fact that it doesn't allow one to specify the stack size.
Thankfully, there's the clone3
syscall, which provides the API I want (and, as a fun bonus, is even more low-level). However, it doesn't work quite the same: instead of supplying a function pointer for it to call, it forks the process much like fork
, resulting in two processes continuing after the syscall returns.
My question is this: if I call a function that returns !
(and doesn't unwind, e.g. std::process::exit
), can I rely on no drops being inserted before it? Otherwise, I'll get trivial and unavoidable double-drops from unrelated variables getting dropped in both threads.
For example, is the following sound?
fn main() {
let foo = String::from("foo");
let result = clone3(...); // Thin wrapper around the syscall
// `result = 0` iff this is the child
if result == 0 {
// Run some fancy thread code
// Can I rely on foo getting "forgotten" here? Can I rely on *all*
// prior state (that's not explicitly dropped) getting forgotten?
// Or could something potentially get dropped?
std::process::exit(0);
}
drop(foo);
}
I'd also be curious what stability guarantees there are, whatever the semantics that are currently applied.