4 ms·
Almost all code ends up going through unsafe, as calling into the OS to do any I/O ends up being unsafe. A warning like this would warn on almost all useful pro
by steveklabnik 8y ago
Almost all code ends up going through unsafe, as calling into the OS to do any I/O ends up being unsafe. A warning like this would warn on almost all useful programs, making the warning useless.
You already don't need to think about it. If you're not calling unsafe yourself, then it's not your job.
- amelius 8y agoWhat I meant is that sometimes, when you have to write unsafe code, it's easier to make it not thread-safe. Then later on, someone uses that piece of code and tries to parallelize it, and runs into problems. This can be prevented with language support.
- steveklabnik 8y agoRust does disallow you from doing some kinds of unsafe operations between threads, unless you explicitly opt in. That said, unsafe is not generally more convenient than safe and so people empirically don’t do this in the first place.
- amelius 8y agoLet me ask you then: would you use a Rust library in multithreaded code, without checking if that library is thread-safe? Wouldn't you like your compiler to tell you?
- steveklabnik 8y agoAll the time. The compiler does tell you if it’s thread safe. That’s the point.
- GolDDranks 8y agoThere is so called marker traits Send and Sync that are used to track whether something is tread-safe or not. https://doc.rust-lang.org/beta/nomicon/send-and-sync.html https://doc.rust-lang.org/beta/nomicon/send-and-sync.html Regardless of whether you use unsafe or not, thread safety is tracked with these and they allow the compiler to detect and prohibit data races.