When Lock-Free Still Isn't Enough: An Introduction to Wait-Free Programming and Concurrency Techniques
std::atomic does and what it is used for • You’ve heard of lock-free programming and know what a compare_exchange is Daniel Anderson -- danielanderson.net4 Our motivating problem • Required by std::weak_ptr::lock uint64_t read() { return counter.load(); } std::atomic counter{1}; }; compare_exchange(expected&, desired) { if (current_value == expected) { current_value = desired; uint64_t read() { return counter.load(); } std::atomic counter{1}; }; compare_exchange(expected&, desired) { if (current_value == expected) { current_value = desired; 0 码力 | 33 页 | 817.96 KB | 5 月前3Multi Producer, Multi Consumer, Lock Free, Atomic Queue
c_queueC++ Atomic Operations / CPU instructions ● std::atomic- provides load / store / compare_exchange ● std::atomic ::is_always_lock_free ● Load and Store of aligned 8 bytes ● CAS ( old-expected data_entry{static_cast ((wr_index << 1) | 1U), d}; if (_array[wr_index].compare_exchange(e, data_entry)) { // <=== DWCAS atomic instruction if constexpr (!lazy_push) empty_entry{static_cast ((rd_index + _array.size()) << 1U)}; if (_array[rd_index].compare_exchange(e, empty_entry)) { // <=== DWCAS atomic instruction d = e.get_data(); 0 码力 | 54 页 | 886.12 KB | 5 月前3Lock-Free Atomic Shared Pointers Without a Split Reference Count? It Can Be Done!
collection in C++ Some assumed knowledge • You’ve heard of lock-free programming and know what a compare_exchange is • You know roughly what atomic does and what it is used for • You’ve heard of shared_ptr collection in C++ Some assumed knowledge • You’ve heard of lock-free programming and know what a compare_exchange is • You know roughly what atomic does and what it is used for • You’ve heard of shared_ptr shared_ptrload() • bool compare_exchange_weak(shared_ptr & expected, shared_ptr desired) • … compare_exchange(expected, desired) { if (current_value == expected) current_value = desired else expected 0 码力 | 45 页 | 5.12 MB | 5 月前3Rust原子操作高性能实践 Rust Atomic Deep Dive - 王璞
operations? Atomic operation best practice Outline What are Atomic Operations in Rust? fn compare_exchange( &self, // AtomicI8 current: i8, new: i8, success: Ordering, failure:0 码力 | 19 页 | 1.88 MB | 1 年前3C++ Memory Model: from C++11 to C++23
Is += a single/atomic instruction? How about ++? • How many reads/writes are needed for compare_exchange? What if it fails • foo(int volatile n) int volatile foo() are meaningless.Alex Dathskovsky0 码力 | 112 页 | 5.17 MB | 5 月前3PostgreSQL 13.13 Documentation
s390x, and very possibly there are other cases on other platforms. • Improve code generated for compare_exchange and fetch_add operations on PPC (Noah Misch) • Fix relation cache memory leaks with RLS policies Visual Studio 2019 (Haribabu Kommi) • Add build support for MSYS2 (Peter Eisentraut) • Add compare_exchange and fetch_add assembly language code for Power PC compilers (Noah Misch) • Update Snowball0 码力 | 2782 页 | 13.00 MB | 1 年前3PostgreSQL 13.14 Documentation
s390x, and very possibly there are other cases on other platforms. • Improve code generated for compare_exchange and fetch_add operations on PPC (Noah Misch) • Fix relation cache memory leaks with RLS policies Visual Studio 2019 (Haribabu Kommi) • Add build support for MSYS2 (Peter Eisentraut) • Add compare_exchange and fetch_add assembly language code for Power PC compilers (Noah Misch) • Update Snowball0 码力 | 2940 页 | 12.89 MB | 1 年前3
共 7 条
- 1