C++ Memory Model: from C++11 to C++23Memory Model C++11 – C++23About Me: alex.dathskovsky@speedata.io www.linkedin.com/in/alexdathskovsky https://www.cppnext.comAlex Dathskovsky | alex.dathskovsky@speedata.io | www.linkedin.com/in/a dathskovsky@speedata.io | www.linkedin.com/in/alexdathskovsky Synchronization Tools ● Static: from C++11 static variables initialization is magicAlex Dathskovsky | alex.dathskovsky@speedata.io | www.linkedin0 码力 | 112 页 | 5.17 MB | 6 月前3
Modern C++ Iterators++p) { std::cout << *p << '\n'; } 30 40 50 60 70 10 20 pos begin() end() c v i d e e ++ C++98/C++11 arr: ©2023 by josuttis.com 6 C++ Iterators: Generalization of Pointers that Iterate • Iterate arr+4; ++p) { std::cout << *p << '\n'; } 30 40 50 60 70 10 20 pos begin() end() c v i d e e ++ C++11 p: arr: Nico Josuttis Modern C++ 2023-10-03 @CppCon 3©2023 by josuttis.com 7 C++ Half-Open Range arr; p < arr+4; ++p) { std::cout << *p << '\n'; } 30 40 50 60 70 10 20 pos begin() end() ++ C++11 auto pos = v.end(); // OK std::cout << *pos; // Undefined Behavior p: arr: ©2023 by josuttis.com0 码力 | 24 页 | 1.93 MB | 6 月前3
cppcon 2021 safety guidelines for C parallel and concurrencyUL4600 Object Tracking ● RISC-V Datacenter/Cloud Computing Chair ● http://wongmichael.com/about ● C++11 book in Chinese: https://www.amazon.cn/dp/B00ETOV2OQ We build GPU compilers for some of the most ++: checkable rules • Common Weakness Enumeration: a mix Many Safety Critical APIs • Safe but not C++11/14/17/20 • Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and the reference despite its age • For automated static analysis tools • Aimed for embedded domains • C++11/14/17/20 but not safe • High Integrity C++ Coding Standard Version 4.0, Programming Research Ltd0 码力 | 52 页 | 3.14 MB | 6 月前3
Cooperative C++ Evolution30 years syntax… #2 ? “bubble of new code” that doesn’t exist today What if we could do “C++11 feels like a new language” again, for the whole language?5 Major improvement via directed evolution enum language type C++11: extended enum and added enum class Can specify underlying type, enumerators are scoped, no implicit conversion .29 C: Special enum language type C++11: extended enum and class + only valid values Automates what we already teach today30 C: Special enum language type C++11: extended enum and added enum class Can specify underlying type, enumerators are scoped, no implicit0 码力 | 85 页 | 5.73 MB | 6 月前3
Back to Basics: Concurrencyodwyer@gmail.com Arthur O’Dwyer 2020-09-18Outline ● What is a data race and how do we fix it? [3–12] ● C++11 mutex and RAII lock types [13–23] Questions? ● condition_variable [24–28] ● Static initialization sleep(200ms); Is this a legal optimization for a C++ compiler to perform? Prior to C++11, the answer was “no idea.” The C++11 answer is unambiguously “yes.” No other thread is allowed to look at the variable thread In C++03 pthreads, you’d create a new thread by calling a third-party library function. In C++11, the standard library “owns” the notion of creating new threads. To create a thread, you create a0 码力 | 58 页 | 333.56 KB | 6 月前3
Back to Basics: Smart Pointersresource during a copy operation std::unique_ptr C++11 ▪ Owns the resource exclusively ▪ Can not be copied ▪ Deals with non-copy objects std::shared_ptr C++11 ▪ Shares a resource ▪ Supports an reference resource and manages it ▪ Deletes the resource if the reference counter becomes 0 std::weak_ptr C++11 ▪ Borrows the resource ▪ Helps to break cyclic references ▪ Doesn't change the reference counter Available Since new 2.93 s C++98 std::unique_ptr 2.96 s C++11 std::make_unique 2.84 s C++14 std::shared_ptr 6.00 s C++11 std::make_shared 3.40 s C++11 19Smart Pointer ▪ Further information: ▪ std::unique_ptr0 码力 | 30 页 | 625.43 KB | 6 月前3
Back to Basics: Lambda Expressionsfunction object 13Lambda Expressions ● Definition of a Lambda Expression ○ first introduced in C++11 ○ syntax for a lambda expression consists of specific punctuation ■ [] () {} ○ key elements ■ [capture of the closure auto myLamb = [&x] ( ) { return ++x; }; 20Lambda Expressions ● Capture Clause ○ C++11 ■ capture by value or reference ○ C++14 ■ generalized capture was added 21Lambda Expressions ● move occurs when the lambda expression is evaluated 22Lambda Expressions ● Capture Clause ○ C++11 ■ [this] ■ captures this pointer by value ○ C++14 ■ [self = *this] ■ capture *this object by value0 码力 | 48 页 | 175.89 KB | 6 月前3
The Roles of Symmetry And Orthogonality In DesignOrthogonality In Design cppcon 2021 Cheating Symmetry: std::move Motivation for std::move (since C++11): To violate symmetry for gains in efficiency (i.e., state pilfering) Bar bar0; //...populate bar0 orthogonal (pilfered-from and pilfered-into objects are related) Motivation for std::move (since C++11): To violate symmetry for gains in efficiency (i.e., state pilfering) Bar bar0; //...populate bar0 NRVO) to transfer instance • “Pilfer” or transfer object state: • xvalues (&&) (since C++11) • std::move<> (since C++11) • “Light-reference” state managed elsewhere: • std::string_view (since C++17) • std::span0 码力 | 151 页 | 3.20 MB | 6 月前3
Back to Basics: Classic 9STLwork; adding the original associative containers • 1998, first ISO C++ Standard published • 2011, C++11 is published, and with some new containers 13CppCon 2021 – Back to Basics: Classic STL Copyright • array (C++11) • forward_list (C++11) • Associative containers • map • set • multimap • multiset 21 • Unordered associative containers • unordered_map (C++11) • unordered_set (C++11) • unordered_multimap unordered_multimap (C++11) • unordered_multiset (C++11) • Container adaptors • queue • stack • priority_queueCppCon 2021 – Back to Basics: Classic STL Copyright © 2021 Bob Steagall Iterators Overview0 码力 | 75 页 | 603.36 KB | 6 月前3
C++20: An (Almost) Complete Overviewconcurrent_stack { struct Node { T t; shared_ptrnext; }; atomic_shared_ptr head; // in C++11: remove "atomic_" and use special // functions every time you touch head public: class reference shared_ptr p; }; auto find(T t) const { auto p = head.load(); // C++11: atomic_load(&head) while (p && p->t != t) p = p->next; return reference(move(p)); } } // C++11: atomic_compare_exchange_weak(&head, &p->next, p); } void pop_front() { auto p = head.load(); while (p && !head.compare_exchange_weak(p, p->next)) { } // C++11: atomic_ 0 码力 | 85 页 | 512.18 KB | 6 月前3
共 80 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8













