Does Rust handle anything with memory barriers? I can handle concurrency, interrupt handlers, etc, but memory barriers always trouble me.
Re:Linux kernel in-tree Rust support
by steveklabnik on Saturday July 11, 2020 @12:55PM
(#23803557)
It will force your code to be memory safe, but it can't enforce that you have the correct semantics.
https://doc.rust-lang.org/std/sync/atomic/fn.fence.html exists, but Rust can't force you to say, use the correct ordering.
Right, so no different than C in this regard.
Really, you should rarely be using raw memory barriers even in C, IMO. The C11/C++11 atomics model (which Rust also uses) is substantially nicer. Though, unfortunately, still extremely tricky to get right.
Having the compiler enforce some of these invariants for you might well end up making writing the code easier, not harder. Rust has a steep learning curve, that's absolutely true, but in my experience I feel a lot more at ease writing complicated parallel code with complicated ownership models in Rust than in C.
C is a trickster: in practice if you want to write correct C code you have to use a memory model very similar to that of Rust, the main difference being that Rust forces you to do it (mostly) right whereas C will gladly let you write completely broken code.