2 ms·
C compilers already optimize for CPU instruction order on multi-issue pipelined CPUs. Multithreading in C, however, is left as an exercise to the coder. You man
by voidbert 3y ago
C compilers already optimize for CPU instruction order on multi-issue pipelined CPUs. Multithreading in C, however, is left as an exercise to the coder. You manually need to use locks and make sure no race conditions are occurring, which is hard in large programs. Also, no function is thread safe unless you're explicitly told so.
I don't use Rust very much, so someone correct me if I'm wrong, but the ownership and borrowing system makes the compiler fail if you transfer data to child threads and then use it in the main one. It's just safer to parallelize code, and you'll do it! (unlike in C, where it may be better not to risk it)
- usrbinbash 3y ago> Multithreading in C, however, is left as an exercise to the coder. Well, it is a systems implementation language, so it cannot, and should not, impose too many guardrails. And yes, sometimes systems implementations need to do things that even all the checks built into Rust would scream loudly about. Rust, which is also meant to implement system code with, acknowledges this duality, that's why the `unsafe` keyword exists. And while the complexity of avoiding race conditions does exist, we have good solutions for it. One such solution is CSP. Passing state and synchronizing via messages is an incredibly natural and logical way to think about the structure of concurrent codebases.
- kaba0 3y agoRust is also a “system implementation” language.
- usrbinbash 3y agoYes? I said so in my above post? > Rust, which is also meant to implement system code with
- kaba0 3y agoRust prevents data races by the help of the borrow checker (by preventing multiple threads using the same resource concurrently), and it also helps by disallowing sending objects to other threads if they were not marked as capable of such.