4 ms·
Basic question — when you're writing a kernel in Rust with its own threading implementation, how does the rust compiler even know what threads are? It has to id
by acconsta 11y ago
Basic question — when you're writing a kernel in Rust with its own threading implementation, how does the rust compiler even know what threads are? It has to identify thread boundaries for send/sync, right?
- dbaupp 11y agoThe compiler has no concept of what a thread is anywhere, even in the standard library. The safety is imposed by careful bounds on exactly the right functions: those that interact/create new threads, e.g. std::thread::spawn has signature: pub fn spawn<F, T>(f: F) -> JoinHandle<T> where F: Send + 'static + FnOnce() -> T, T: Send + 'static Other than implementations of `Send`/`Sync` themselves, this is essentially the only function in std that needs to bound by them. The same approach can be used in a kernel context, e.g. place bounds on the functions that create (or, at least, initialise interaction between) concurrently executing pieces of code.