Received my O’Reily book on Rust Programming and have been pumped from the start in my readings. I’m trying to code as much as possible through my readings and clear my confusion from the start. I have a few questions on some comments that the author makes in Chapter 2 which is really a slight intro to Rust. I have much yet to explore but I wanted to clear up some confusion.
In the section where it introduces some advantages of currency over C/C++ it gives the following bullet point.
- “Rust ensures that you can’t access the data except when you’re holding the lock, and releases the lock automatically when you’re done. In C/C++, the relationship between a mutex and the data it protects is left to the comments.”
I’m not understanding what it means by comments.
I’m a bit new to multi-threading (in C/C++) but I understand the concept of a mutex so is my understanding correct that in Rust it will automatically release the mutex for you and in C/C++ you have to manually do this yourself?
Lastly, there is another statement below that sounds like a very strong statement so I wanted to verify.
- “No matter how elaborate your program gets if it compiles, it is free of data races. All Rust functions are thread-safe”
What does it mean by “Rust Functions”? Is a Rust function in the context of a function in a crate written by someone else? Is a Rust function a function in it’s standard libs? Is a Rust function a function that I write in my own context for wrapping up functionality? Or is a Rust function all the above meaning any function statement starting with “fn” written in Rust?
I’m assuming from this point on Rust is hands down 100% excellent at writing thread safe code and if it compiles I’m free of data races and is hereby announced “thread safe”?
Thanks guys for your help