-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider avoiding AtomicT
recommendation
#11
Comments
Even though it can be arguable, I find it useful that the cheat sheet includes many memory containers (smart pointers, wrapper types). The introductory materials / books on Rust that I have met so far fail to provide a coherent mental model on, so to speak, memory management tools of the language. But that could be useful for a newbie to be exposed to such a mental model from the beginning, not after months or years of studying the language. This cheat sheet is an excellent attempt to fill this gap. So I'd rather argue for updating, extending, and refining it, rather than removing types present in the language from it. If someone ever commits to such a task, the only other existing attempts I'm aware of can be found in:
Two more partially related resources on building a correct mental model of the ownership:
Aside, for those interested in what Atomics are about:
|
Atomics are not memory containers.
Atomics should not be part of this mental model. If a Rust programmer never uses atomics in their lifetime, they will almost surely not be worse off for it, unless they’re implementing low-level synchronization primitives in which case they’ll know about atomics already. This is not information that is important to teach beginners, but can be actively harmful.
I’m really confused. Ownership has nothing to do with atomics. |
Do you agree they could be called wrapper type? (This term was used in the quoted text.)
It's clear this is the statement you stick to. I've presented a different point of view for consideration by any future reader and for the sake of the issue discussion.
The quoted "partially related resources" are supplementary ones. They refer a potentially interested reader to additional materials on building a correct mental model of Rust. |
I mean, depends on context: when listing all the interior mutable containers, sure, when listing data structures, no, since data structures are expected to be generic. |
See this discussion for context: rust-lang/rust-clippy#4295
Basically,
AtomicT
is not just “a fastMutex<T>
”, it has many additional properties such as it not supporting locking and it acceptingOrdering
parameters. It is often harmful to recommendAtomicT
as a direct replacement forMutex<T>
, because people can easily make assumptions about how they behave that turn out to not be correct, since their actual behaviour is quite subtle (even just withSeqCst
, the model of aMutex<T>
is far simpler as it allows arbitrary mutation while in the “locked” state). I seeAtomicT
as beïng a very low-level primitive for implementing concurrent data structures; it’s mostly too complex for high-level code. Generally, if someone understands Rust well enough to correctly know how to use atomics, they would not need this chart in the first place.The text was updated successfully, but these errors were encountered: