Lock-Free Atomic Shared Pointers Without a Split Reference Count? It Can Be Done!Atomics and concurrency patterns • How existing atomicare implemented (the split reference count technique) • Deferred reclamation, i.e., garbage collection in C++ Some assumed knowledge Atomics and concurrency patterns • How existing atomic are implemented (the split reference count technique) • Deferred reclamation, i.e., garbage collection in C++ Some assumed knowledge danielanderson.net std::shared_ptr (the basics) T* ptr; shared_ptr s1: control_block: atomic ref_count = 1; … control_block* ctrl; T12 Daniel Anderson -- danielanderson.net std::shared_ptr (the 0 码力 | 45 页 | 5.12 MB | 6 月前3
C++23: An Overview of Almost All New and Updated Features2nd, 3rd, 4th, and 5th Edition Co-author of C++ Standard Library Quick Reference& C++17 Standard Library Quick Reference Founder of the Belgian C++ Users Group (BeCPP) C++204 Agenda C++23 = 0, count = data.size(); i < count; ++i) { /* ... */ } Doesn’t compile: i is deduced as int, but count is size_t Solution: use uz literal: for (auto i = 0uz, count = data.size(); i < count; ++i) resize_and_overwrite(count, op) Resizes a string and sets new content by invoking an operation Used if performance is critical Effect: If count <= size(), erase the last size() - count elements 0 码力 | 105 页 | 759.96 KB | 6 月前3
A Crash Course in Calendars, Dates, Time, and Time Zones2nd, 3rd, 4th, and 5th Edition Co-author of C++ Standard Library Quick Reference& C++17 Standard Library Quick Reference Founder of the Belgian C++ Users Group (BeCPP) C++203 Agenda Compile-Time { d3 + d4 }; cout << format("{}min + {}sec = {}min or {}sec", d3.count(), d4.count(), d5.count(), d6.count()); // 10min + 30sec = 10.5min or 630sec14 Durations – Operations Converting of d7 to minutes. duration> d8 { d7 }; cout << format("{}sec = {}min", d7.count(), d8.count()); // 30sec = 0.5min duration > d8 { d7 }; // minutes // Error 0 码力 | 43 页 | 551.60 KB | 6 月前3
C++20: An (Almost) Complete OverviewEdition (C++20) coming later this year Co-author of C++ Standard Library Quick Reference& C++17 Standard Library Quick Reference Founder of the Belgian C++ Users Group (BeCPP)3 C++20 C++20 is big! Lots C++11: remove "atomic_" and use special // functions every time you touch head public: class reference { shared_ptrp; }; auto find(T t) const { auto p = head.load(); atomic_load(&head) while (p && p->t != t) p = p->next; return reference(move(p)); } auto front() const { return reference(head); } void push_front(T t) { auto p = make_shared (); 0 码力 | 85 页 | 512.18 KB | 6 月前3
Working with Asynchrony Generically: A Tour of C++ Executorsinput sender into a variant of tuples. bulk(sender, size, fn) → sender … launches a bulk operation. split(sender) → sender … permits multiple receivers to be connected (forks the execution graph). done */ } Because of the nested scopes, it’s safe to pass locals by reference to callees... … no dynamic allocation or reference counting needed.64 SENDER/RECEIVER IS ALSO STRUCTURED CONCURRENCY0 码力 | 121 页 | 7.73 MB | 6 月前3
C++高性能并行编程与优化 - 课件 - 14 C++ 标准库系列课 - 你所不知道的 set 容器和所包装的迭代器一致 https://en.cppreference.com/w/cpp/iterator/random_access_iterator https://www.cplusplus.com/reference/iterator/istream_iterator 包含关系:前向迭代器>双向迭代器>随机访问迭代器 这意味着如果一个 STL 模板函数(比如 std::find )要求迭代器是前向迭代器即可,那么也可 还有一种更直观的写法: • set.count(x) != 0 • count 返回的是一个 int 类型,表示 集合中相等元素的个数。 • 等等,不是说 set 具有去重的功能,不会 有重复的元素吗?为什么标准库让 count 计算个数而不是直接返回 bool… 因为他们 考虑到接口的泛用性,毕竟 multiset 就不 去重。对于能去重的 set , count 只可能 返回 0 或 1 。 • size_t count(int const &val) const; 从 set 中删除指定元素 • set.erase(x) 可以删除集合中值为 x 的元素。 • erase 返回一个整数,表示被他删除元素的个 数。 • 个数为 0 就说明集合中没有该元素,删除失败 。 • 个数为 1 就说明集合中存在该元素,删除成功 。 • 这里的“个数”和 count 的情况很像,因为0 码力 | 83 页 | 10.23 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 15 C++ 系列课:字符与字符串size_t find(const char *s, size_t pos = 0) const; • size_t find(const char *s, size_t pos, size_t count) const; • 为什么最后两个重载没有标记 noexcept ?历史原因,实际上 find 函数都是不会抛出异常的,他找不到只会返回 -1 。 find 寻找子字符串 • find(‘c’) find_first_of(“ \t\v\f\n\r”) 。 https://www.geeksforgeeks.org/isspace-in-c-and-its-application-to-count-whitespace-characters/ find_first_of 应用案例:按空格分割字符串 find_first_not_of 寻找不在集合内的字符 举一反三: find_last_of 强引用胖指针: string • 刚刚说的 string 容器,是掌握着字符串生命周期( lifespan )的胖指针。 • 这种掌管了所指向对象生命周期的指针称为强引用( strong reference )。 • 这个强引用的强,体现在哪里? • 当 string 容器被拷贝时,其指向的字符串也会被拷贝(深拷贝)。 • 当 string 容器被销毁时,其指向的字符串也会被销毁(内存释放)。0 码力 | 162 页 | 40.20 MB | 1 年前3
Making Libraries Consumable for Non-C++ Developers“width”. Explicitly state/document/reference function conventions. • Defining a macro for calling conventions is a great start. For example, MYLIB_CCONV. • Reference: llvm - CallingConv.h • Don’t throw memory management”. - Reference counted - C++ – std::shared_ptr- Python - Objective-C (manual or automatic – see ARC) - Swift - COM – AddRef()/Release() - Non-Reference counted - .NET - JVM have been deleted here, if allocator was known.Memory model – Reference Counted Memory lifetime is tracked explicitly through reference counting. This typically means allocation locations are static 0 码力 | 29 页 | 1.21 MB | 6 月前3
Что нужно знать об архитектуре ClickHouse, чтобы его эффективно использоватьтоп-10 рефереров за неделю. SELECT Referer, count(*) AS count FROM hits WHERE CounterID = 1234 AND Date >= today() - 7 GROUP BY Referer ORDER BY count DESC LIMIT 10 Типичный запрос в системе веб-аналитики из Distributed таблицы CSV 227 Gb, ~1.3 млрд строк SELECT passenger_count, avg(total_amount) FROM trips GROUP BY passenger_count NYC taxi benchmark Шардов 1 3 140 Время, с. 1,224 0,438 0,043 Ускорени0 码力 | 28 页 | 506.94 KB | 1 年前3
使用硬件加速Tokio - 戴翔Senders Receive Receivers Perf Gaps: CAS(Compare And Swap) can't perfectly scale with core count. Tokio Channel • Each worker has own run queue • Steal when own run queue is empty From the channel scales with core count much better than SW channels • Core count >2 shows advantage From the Pictures: • SW channels depicted in red and yellow line drop with the core count increasing because of threads sending to one place. Conclusion: • DLB channel is more stable than SW channels • Core count >2 shows advantage From the Pictures: • SW channels depicted in origin and purple line, drop with0 码力 | 17 页 | 1.66 MB | 1 年前3
共 22 条
- 1
- 2
- 3













