There's more...

Because SeqCst is good enough for most applications and the complexity involved in all other orderings, we are not going to look at any others. Don't be disappointed, however—Rust uses nearly the same atomic layout and functionality as C++, so there are plenty of sources to tell you how complex the issue really is. Anthony Williams, author of the well-known book C++: Concurrency In Action (http://www.cplusplusconcurrencyinaction.com/), uses an entire 45 pages (!) to simply describe all the atomic orderings and how to use them. An additional 44 pages go into showing examples of all of these orderings. Does an average program benefit from this level of dedication? Let's look at the man's own words, with the background knowledge that std::memory_order_seq_cst is how C++ calls SeqCst:

The basic premise is: do not use anything other than std::memory_order_seq_cst (the default) unless (a) you really really know what you are doing, and can prove that the relaxed usage is safe in all cases, and (b) your profiler demonstrates that the data structure and operations you are intending to use the relaxed orderings with are a bottleneck.

Source: https://stackoverflow.com/a/9564877/5903309

In short, you should wait to learn about the different kinds of orderings until you have a very good reason to use them. This is, by the way, also the approach of Java, which makes all variables marked as volatile behave in a sequentially consistent way.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.190.182