C++ programmer's guide to undefined behavior: part 7 of 11

Your attention is invited to the seventh part of an e-book on undefined behavior. This is not a textbook, as it's intended for those who are already familiar with C++ programming. It's a kind of C++ programmer's guide to undefined behavior and to its most secret and exotic corners. The book was written by Dmitry Sviridkin and edited by Andrey Karpov.

C++ programmer's guide to undefined behavior: part 7 of 11

by Dmitry Sviridkin

From the article:

In the early '70s, Ken Thompson, Dennis Ritchie, and Brian Kernighan worked on the first versions of C and Unix. They made a decision that resonates with pain, suffering, bugs, and inefficiency today, 50 years later. They decided that developers were to write strings—variable-length data—in a sequence that terminated with a null character. Assembly has it, and C should have it too, if people call it "high-level assembly"! After all, the poor old PDP has limited memory: it's better to have one extra byte per string than 2, 4, or even all 8 bytes (depending on the platform) to store the size... Nah, it's better to have a byte at the end! But even other languages store a size, a reference, or a pointer to the data...

Meeting C++ 2024: the last hybrid C++ conference?

Like last year sharing my thoughts on that Meeting C++ 2024 is the only hybrid C++ conference.

Meeting C++ 2024: the last hybrid C++ conference?

by Jens Weller

From the article:

While I'm happy that Meeting C++ 2024 is not the last online conference, I do have once again to wonder if its the last hybrid one.

Once again I'd like to document my thoughts on running a hybrid conference, and also ask the C++ community for the support if you value such an offer being available world wide. In the end the numbers of this years conference will once again decide if I think that continueing is worth it.

Its easier to run a conference without a live stream...

The Definitive Guide to std::expected in C++ -- John Farrier

std::expected is a powerful feature introduced in C++23 that offers a modern, type-safe alternative to traditional error-handling methods.  std::expected allows developers to represent a value or an error in a single object, simplifying the handling of success and failure scenarios in a clean and readable way.

The Definitive Guide to std::expected in C++

John Farrier

From the article:

std::expected is an addition to the C++ standard library that provides a way to return and propagate errors without using exceptions. It represents a value or an error and is similar to the Result type in Rust. This guide covers its use, benefits, and comparison with other error handling techniques, helping developers to write more robust and readable code.

CGAL Released, Computational Geometry Algorithms Library -- Laurent Rineau

The CGAL Open Source Project is pleased to announce the recent releases of CGAL versions 5.5.5, 5.6.2, 6.0, and 6.0.1.

New CGAL versions: 5.5.5, 5.6.2, 6.0, and 6.0.1

by Laurent Rineau

From the article

CGAL version 6.0

CGAL version 6.0 was released on September 27, 2024. Following the discovery of early issues, version 6.0.1 was subsequently released on October 22, 2024.

This version is a major release, with many new features and improvements.

General changes

  • C++17 Requirement: CGAL 6.0 requires a C++17 compatible compiler.
  • GMP/MPFR Optional: GMP/MPFR are no longer mandatory; Boost.Multiprecision can be used.
  • Qt6 Demos: All demos are now based on Qt6.
  • Polyhedral Surface: The demo has been renamed to “CGAL Lab” and moved to its own directory in demo/Lab/.

New Packages

Breaking Changes

  • CMake Changes: UseCGAL.cmake removed; use CGAL::CGAL target instead.
  • Kernel: Replaced boost::variant with std::variant and boost::optional with std::optional in the intersection functions.

Enhancements

  • AABB Tree: Now supports 2D and 3D primitives.

Passing C++ STL Strings vs. String Views at the Windows C API Boundary -- Giovanni Dicanio

A common question that is often asked is whether C++ STL string objects (like std::string/wstring) or string views (e.g. std::wstring_view) should be passed as string parameters at Windows C-interface API boundaries. The following articles tries to shed some light on this subject, answering that question:

Passing C++ STL Strings vs. String Views as Input Parameters at the Windows C API Boundary

by Giovanni Dicanio

From the article:

Passing STL std::[w]string objects at Win32 API boundaries is common for C++ code that calls into Win32 C-interface APIs. When is it safe to pass *string views* instead?

(...) the code will work fine. In fact, the wstring::c_str() method is guaranteed to return a null-terminated C-style string pointer.

On the other hand, if you pass a string view like std::wstring_view in that context, you’ll likely get some subtle bugs! Try experimenting with the above API and something like “Connie is learning C++” and string views!

 

Code Generation in Rust vs C++26 -- Barry Revzin

TPWGDVRj_400x400.jpgExploring how different languages solve the same problem often reveals interesting contrasts, especially when it comes to implementing powerful features like reflection. While C++26 aims to introduce introspection and code generation via P2996 and P3294, Rust’s approach using its derive macros offers a mature solution for code generation, even without introspection, highlighting different philosophies in language design and their practical applications.

Code Generation in Rust vs C++26

by Barry Revzin

From the article:

One of the things I like to do is compare how different languages solve the same problem — especially when they end up having very different approaches. It’s always educational. In this case, a bunch of us have been working hard on trying to get reflection — a really transformative language feature — into C++26. Fundamentally, reflection itself can be divided into two pieces:

  1. Introspection — the ability to ask questions about your program during compilation
  2. Code Generation — the ability to have your code write new code

P2996 (Reflection for C++26) is the (huge) core proposal that fundamentally deals with the first problem, along with setting the foundation for being able to extend this feature in lots of different directions in the future, including generation (for which our design is P3294). But introspection, while valuable, is only half of the piece. Andrei Alexandrescu went so far as to claim in his CppCon talk that introspection without generation is useless.

PVS-Studio 7.33: SN-DBS support

PVS-Studio 7.33 has been released. Check out the latest features, including SN-DBS support, C# user annotations, and other exciting updates! See more details in this note.

PVS-Studio 7.33: SN-DBS support

by Valerii Filatov

From the article:

To enhance the integration of PVS-Studio with Unreal Engine, we've introduced support for SN-DBS, a distributed build system. These changes apply to Unreal Engine 5.5. Learn more about using PVS-Studio with Unreal Engine in the documentation.

2024-10 Mailing Available

The 2024-10 mailing of new standards papers is now available.

 

WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup
N4991 2025 Sofia Meeting Invitation and Information Vassil Vassilev 2024-10-16 2024-10   All of WG21
N4993 Working Draft, Programming Languages -- C++ Thomas Köppe 2024-10-16 2024-10   All of WG21
N4994 Editors' Report, Programming Languages -- C++ Thomas Köppe 2024-10-16 2024-10   All of WG21
P0260R11 C++ Concurrent Queues Detlef Vollmann 2024-10-12 2024-10 P0260R10 SG1 Concurrency and Parallelism,LEWG Library Evolution
P0707R5 Metaclass functions for generative C++ Herb Sutter 2024-10-15 2024-10 P0707R4 SG7 Reflection,EWG Evolution
P0876R18 fiber_context - fibers without scheduler Oliver Kowalke 2024-10-16 2024-10 P0876R17 EWG Evolution,CWG Core,LWG Library
P1144R12 std::is_trivially_relocatable Arthur O'Dwyer 2024-10-14 2024-10 P1144R11 EWGI SG17: EWG Incubator
P1255R14 A view of 0 or 1 elements: views::nullable And a concept to constrain maybes Steve Downey 2024-10-16 2024-10 P1255R13 LEWG Library Evolution,LWG Library
P1306R3 Expansion statements Dan Katz 2024-10-14 2024-10 P1306R2 EWG Evolution
P1494R4 Partial program correctness S. Davis Herring 2024-10-15 2024-10 P1494R3 SG22 Compatibility,EWG Evolution,LEWG Library Evolution,CWG Core
P1708R9 Basic Statistics Richard Dosselmann 2024-10-14 2024-10 P1708R8 SG6 Numerics,SG14 Low Latency,SG19 Machine Learning,LEWG Library Evolution,LWG Library
P1729R5 Text Parsing Elias Kosunen 2024-10-15 2024-10 P1729R4 SG16 Unicode,LEWG Library Evolution
P1839R6 Accessing object representations Brian Bi 2024-10-14 2024-10 P1839R5 CWG Core
P1928R12 std::simd - Merge data-parallel types from the Parallelism TS 2 Matthias Kretz 2024-10-11 2024-10 P1928R11 LWG Library
P2079R5 System execution context Lucian Radu Teodorescu 2024-10-16 2024-10 P2079R4 SG1 Concurrency and Parallelism,LEWG Library Evolution
P2319R2 Prevent path presentation problems Victor Zverovich 2024-09-28 2024-10 P2319R1 LEWG Library Evolution
P2392R3 Pattern matching using is and as Herb Sutter 2024-10-16 2024-10 P2392R2 EWG Evolution
P2434R2 Nondeterministic pointer provenance S. Davis Herring 2024-10-15 2024-10 P2434R1 SG22 Compatibility,EWG Evolution,CWG Core
P2645R0 path_view: a design that took a wrong turn Victor Zverovich 2024-10-12 2024-10   LEWG Library Evolution
P2664R8 Proposal to extend std::simd with permutation API Daniel Towner 2024-10-15 2024-10 P2664R7 SG1 Concurrency and Parallelism,LEWG Library Evolution
P2688R3 Pattern Matching: `match` Expression Michael Park 2024-10-16 2024-10 P2688R2 EWG Evolution
P2719R1 Type-aware allocation and deallocation functions Louis Dionne 2024-10-16 2024-10 P2719R0 EWG Evolution
P2728R7 Unicode in the Library, Part 1: UTF Transcoding Zach Laine 2024-10-07 2024-10 P2728R6 SG9 Ranges,SG16 Unicode,LEWG Library Evolution
P2746R6 Deprecate and Replace Fenv Rounding Modes Hans Boehm 2024-10-14 2024-10 P2746R5 SG6 Numerics,LEWG Library Evolution
P2769R3 get_element customization point object Ruslan Arutyunyan 2024-10-16 2024-10 P2769R2 LEWG Library Evolution
P2786R8 Trivial Relocatability For C++26 Mungo Gill 2024-10-16 2024-10 P2786R7 EWG Evolution,LEWG Library Evolution
P2841R5 Concept and variable-template template-parameters Corentin Jabot 2024-10-16 2024-10 P2841R4 CWG Core
P2846R4 reserve_hint: Eagerly reserving memory for not-quite-sized lazy ranges Corentin Jabot 2024-10-15 2024-10 P2846R3 LEWG Library Evolution
P2900R10 Contracts for C++ Joshua Berne 2024-10-13 2024-10 P2900R9 EWG Evolution,LEWG Library Evolution
P2900R9 Contracts for C++ Joshua Berne 2024-10-13 2024-10 P2900R8 EWG Evolution,LEWG Library Evolution
P2933R2 std::simd overloads for <bit> header Daniel Towner 2024-10-16 2024-10 P2933R1 LWG Library
P2957R2 Contracts and coroutines Andrzej Krzemieński 2024-10-14 2024-10 P2957R1 SG21 Contracts,EWG Evolution
P2977R2 Build database files Ben Boeckel 2024-10-15 2024-10 P2977R1 SG15 Tooling
P2988R8 std::optional<T&> Steve Downey 2024-10-15 2024-10 P2988R7 LEWG Library Evolution,LWG Library
P2996R6 Reflection for C++26 Barry Revzin 2024-10-09 2024-10 P2996R5 EWG Evolution
P2996R7 Reflection for C++26 Barry Revzin 2024-10-12 2024-10 P2996R6 EWG Evolution
P2998R0 CTAD for function parameter types James Touton 2024-10-15 2024-10   EWGI SG17: EWG Incubator,EWG Evolution
P3019R10 Vocabulary Types for Composite Class Design Jonathan Coe 2024-09-30 2024-10 P3019R9 LEWG Library Evolution,LWG Library
P3045R2 Quantities and units library Mateusz Pusz 2024-10-09 2024-10 P3045R1 SG6 Numerics,SG16 Unicode,LEWG Library Evolution
P3045R3 Quantities and units library Mateusz Pusz 2024-10-15 2024-10 P3045R2 SG6 Numerics,SG16 Unicode,LEWG Library Evolution
P3049R1 node-handles for lists Michael Florian Hava 2024-10-15 2024-10 P3049R0 LEWG Library Evolution
P3070R1 Formatting enums Victor Zverovich 2024-10-13 2024-10 P3070R0 LEWG Library Evolution
P3081R0 Core safety Profiles: Specification, adoptability, and impact Herb Sutter 2024-10-15 2024-10   SG15 Tooling,SG23 Safety and Security,EWG Evolution
P3091R3 Better lookups for `map` and `unordered_map` Pablo Halpern 2024-10-14 2024-10 P3091R2 LEWG Library Evolution
P3094R4 std::basic_fixed_string Mateusz Pusz 2024-10-09 2024-10 P3094R3 SG16 Unicode,LEWG Library Evolution
P3094R5 std::basic_fixed_string Mateusz Pusz 2024-10-15 2024-10 P3094R4 LEWG Library Evolution
P3098R0 Contracts for C++: Postcondition captures Timur Doumler 2024-10-14 2024-10   SG21 Contracts,EWG Evolution
P3100R1 Undefined and erroneous behaviour are contract violations Timur Doumler 2024-10-16 2024-10 P3100R0 SG21 Contracts,SG23 Safety and Security,EWG Evolution
P3100R1 Undefined and erroneous behaviour are contract violations Timur Doumler 2024-10-16 2024-10 P3100R0 SG21 Contracts,SG23 Safety and Security,EWG Evolution
P3125R1 constexpr pointer tagging Hana Dusíková 2024-10-16 2024-10 P3125R0 SG1 Concurrency and Parallelism,LEWG Library Evolution
P3138R3 views::cache_latest Tim Song 2024-10-15 2024-10 P3138R2 LEWG Library Evolution
P3149R6 async_scope -- Creating scopes for non-sequential concurrency Ian Petersen 2024-10-15 2024-10 P3149R5 SG1 Concurrency and Parallelism,LEWG Library Evolution
P3152R0 Add missing constructors and assignment for indirect and polymorphic Jonathan Coe 2024-09-30 2024-10   LEWG Library Evolution
P3160R2 An allocator-aware `inplace_vector` Pablo Halpern 2024-10-14 2024-10 P3160R1 LEWG Library Evolution
P3179R3 C++ parallel range algorithms Ruslan Arutyunyan 2024-10-16 2024-10 P3179R2 SG1 Concurrency and Parallelism,SG9 Ranges,LEWG Library Evolution
P3227R0 Contracts for C++: Fixing the contract violation handling API Gašper Ažman 2024-10-16 2024-10   SG21 Contracts,LEWG Library Evolution
P3237R1 Matrix Representation of Contract Semantics Andrei Zissu 2024-10-16 2024-10 P3237R0 SG21 Contracts
P3261R0 Revisiting `const`-ification in Contract Assertions Joshua Berne 2024-10-02 2024-10   SG21 Contracts,EWG Evolution
P3261R1 Revisiting `const`-ification in Contract Assertions Joshua Berne 2024-10-13 2024-10 P3261R0 SG21 Contracts,EWG Evolution
P3271R1 Function Types with Usage (Contracts for Function Pointers) Lisa Lippincott 2024-10-14 2024-10 P3271R0 SG21 Contracts
P3287R1 Exploration of namespaces for std::simd Matthias Kretz 2024-10-15 2024-10 P3287R0 LEWG Library Evolution
P3293R1 Splicing a base class subobject Barry Revzin 2024-10-13 2024-10 P3293R0 EWG Evolution
P3294R2 Code Injection with Token Sequences Barry Revzin 2024-10-15 2024-10 P3294R1 SG7 Reflection,EWG Evolution
P3295R2 Freestanding constexpr containers and constexpr exception types Ben Craig 2024-10-12 2024-10 P3295R1 LEWG Library Evolution
P3296R2 let_async_scope Anthony Williams 2024-10-14 2024-10 P3296R1 SG1 Concurrency and Parallelism,LEWG Library Evolution
P3298R1 Implicit user-defined conversion functions as operator.() Bengt Gustafsson 2024-10-15 2024-10 P3298R0 EWG Evolution
P3299R2 Range constructors for std::simd Daniel Towner 2024-10-16 2024-10 P3299R1 LEWG Library Evolution
P3310R3 Solving partial ordering issues introduced by P0522R0 Matheus Izvekov 2024-10-14 2024-10 P3310R2 EWG Evolution,CWG Core
P3310R4 Solving issues introduced by P0522R0 Matheus Izvekov 2024-10-15 2024-10 P3310R3 EWG Evolution,CWG Core
P3324R0 Attributes for namespace aliases, template parameters, and lambda captures Tom Honermann 2024-10-14 2024-10   EWG Evolution
P3327R0 Contract assertions on function pointers Timur Doumler 2024-10-16 2024-10   SG21 Contracts,EWG Evolution
P3334R0 Cross Static Variables Coral Kashri 2024-10-15 2024-10   SG7 Reflection,EWGI SG17: EWG Incubator
P3335R2 Structured Core Options René Ferdinand Rivera Morell 2024-10-15 2024-10 P3335R1 SG15 Tooling
P3346R0 thread_local means fiber-specific Nat Goodspeed 2024-10-16 2024-10   EWG Evolution,LEWG Library Evolution
P3348R1 C++26 should refer to C23 not C17 Jonathan Wakely 2024-10-14 2024-10 P3348R0 SG6 Numerics,LEWG Library Evolution
P3349R0 Converting contiguous iterators to pointers Jonathan Wakely 2024-10-16 2024-10   LEWG Library Evolution
P3351R1 views::scan Yihe Li 2024-10-09 2024-10 P3351R0 SG9 Ranges
P3352R0 Taming the Demons (C++ version) - Undefined Behavior and Partial Program Correctness Andrew Tomazos, Martin Uecker 2024-09-19 2024-10   SG22 Compatibility,EWG Evolution
P3355R1 Fix submdspan for C++26 Mark Hoemmen 2024-10-15 2024-10 P3355R0 LWG Library
P3367R0 constexpr coroutines Hana Dusíková 2024-10-16 2024-10   EWG Evolution,LEWG Library Evolution
P3370R1 Add new library headers from C23 Jens Maurer 2024-10-06 2024-10 P3370R0 LEWG Library Evolution
P3371R2 Fix C++26 by making the rank-1, rank-2, rank-k, and rank-2k updates consistent with the BLAS Mark Hoemmen 2024-10-14 2024-10 P3371R1 LEWG Library Evolution
P3372R2 constexpr containers and adapters Hana Dusíková 2024-10-08 2024-10 P3372R1 LEWG Library Evolution
P3375R1 Reproducible floating-point results Guy Davidson 2024-10-08 2024-10 P3375R0 SG6 Numerics,SG14 Low Latency,LEWG Library Evolution
P3376R0 Contract assertions versus static analysis and 'safety' Andrzej Krzemieński 2024-10-14 2024-10   SG21 Contracts,EWG Evolution
P3378R0 constexpr exception types Hana Dusíková 2024-10-14 2024-10   LEWG Library Evolution
P3385R1 Attributes reflection Aurelien Cassagnes 2024-10-14 2024-10 P3385R0 SG7 Reflection
P3386R0 Static Analysis of Contracts with P2900 Joshua Berne 2024-10-15 2024-10   EWG Evolution
P3387R0 Contract assertions on coroutines Timur Doumler 2024-10-09 2024-10   SG21 Contracts,EWG Evolution
P3394R0 Annotations for Reflection Daveed Vandevoorde 2024-10-14 2024-10   SG7 Reflection,EWG Evolution
P3399R0 Adjusting Electronic Polls to a Hybrid Workflow Inbal Levi 2024-10-16 2024-10   LEWG Library Evolution,All of WG21
P3402R1 A Safety Profile Verifying Class Initialization Marc-André Laverdière 2024-10-14 2024-10 P3402R0 SG23 Safety and Security
P3403R0 The Undefined Behavior Question Andrew Tomazos 2024-09-19 2024-10   EWG Evolution
P3404R0 std::at : Range-checked accesses to arbitrary containers Andre Kostur 2024-10-11 2024-10   SG9 Ranges,SG23 Safety and Security
P3405R0 Out-of-order designated initializers Elias Kosunen 2024-09-28 2024-10   EWG Evolution
P3406R0 We need better performance testing Bjarne Stroustrup 2024-09-24 2024-10   All of WG21
P3407R0 Make idiomatic usage of `offsetof` well-defined Brian Bi 2024-10-14 2024-10   EWG Evolution
P3409R0 Enabling more efficient stop-token based cancellation of senders Lewis Baker 2024-10-16 2024-10   SG1 Concurrency and Parallelism
P3411R0 `any_view` Hui Xie 2024-09-29 2024-10   SG9 Ranges,LEWG Library Evolution
P3412R0 String interpolation Bengt Gustafsson 2024-10-15 2024-10   EWGI SG17: EWG Incubator,EWG Evolution
P3413R0 A more flexible optional::value_or (else!) Corentin Jabot 2024-10-15 2024-10   LEWG Library Evolution
P3415R0 Range interface in std::optional breaks code! Andrzej Krzemieński 2024-10-10 2024-10   LEWG Library Evolution
P3416R0 exception_ptr_cast: Add && = delete overload Gor Nishanov 2024-10-14 2024-10   LEWG Library Evolution
P3417R0 Improving the handling of exceptions thrown from contract predicates Gašper Ažman 2024-10-16 2024-10   SG21 Contracts,EWG Evolution
P3419R0 Reflection Syntax Options Summary Michael Levine 2024-10-11 2024-10   SG7 Reflection,EWGI SG17: EWG Incubator,EWG Evolution
P3420R0 Reflection of Templates Andrei Alexandrescu 2024-10-16 2024-10   SG7 Reflection
P3421R0 Consteval destructors Ben Craig 2024-10-12 2024-10   SG7 Reflection,EWG Evolution
P3422R0 Allow main function in named modules   2024-10-09 2024-10   EWG Evolution
P3423R0 Extending User-Generated Diagnostic Messages Yihe Li 2024-10-15 2024-10   EWG Evolution
P3425R0 Reducing operation-state sizes for subobject child operations Lewis Baker 2024-10-16 2024-10   LEWG Library Evolution
P3427R0 Hazard Pointer Synchronous Reclamation Maged Michael 2024-10-11 2024-10   SG1 Concurrency and Parallelism
P3428R0 Hazard Pointer Batches Maged Michael 2024-10-11 2024-10   SG1 Concurrency and Parallelism
P3429R0 Reflection header should minimize standard library dependencies Jonathan Müller 2024-10-16 2024-10   LEWG Library Evolution
P3430R0 simd issues: explicit, unsequenced, identity-element position, and members of disabled simd Matthias Kretz 2024-10-15 2024-10   LEWG Library Evolution
P3433R0 Allocator Support for Operation States Dietmar Kuehl 2024-10-14 2024-10   LEWG Library Evolution
P3435R0 Reflection and meta-programming Jean-Baptiste VALLON HOARAU 2024-10-14 2024-10   SG7 Reflection
P3436R0 Strategy for removing safety-related undefined behavior by default Herb Sutter 2024-10-16 2024-10   SG23 Safety and Security,EWG Evolution
P3437R0 Proposed default principles: Reflect C++, Generate C++ Herb Sutter 2024-10-16 2024-10   SG7 Reflection,EWG Evolution
P3438R0 Make integral overloads of std::to_string constexpr Andreas Fertig 2024-10-13 2024-10   LEWG Library Evolution
P3439R0 Chained comparisons: Safe, correct, efficient Herb Sutter 2024-10-15 2024-10   EWG Evolution
P3440R0 Add n_elements named constructor to std::simd Daniel Towner 2024-10-15 2024-10   LEWG Library Evolution
P3441R0 Rename simd_split to simd_chunk Daniel Towner 2024-10-15 2024-10   LEWG Library Evolution
P3442R0 [[invalidate_dereferencing]] attribute Patrice Roy 2024-10-14 2024-10   SG14 Low Latency,LEWG Library Evolution
P3443R0 Reflection on SG21 2024 Process Ran Regev 2024-10-14 2024-10   SG21 Contracts,EWG Evolution
P3444R0 Memory safety without lifetime parameters Sean Baxter 2024-10-14 2024-10   SG23 Safety and Security
P3445R0 Add utilities for easier type/bit casting in std::simd Daniel Towner 2024-10-16 2024-10   LEWG Library Evolution
P3446R0 Profile invalidation - eliminating dangling pointers Bjarne Stroustrup 2024-10-14 2024-10   SG23 Safety and Security
P3447R0 Profiles syntax Bjarne Stroustrup 2024-10-14 2024-10   SG23 Safety and Security
P3449R0 constexpr std::generator Hana Dusíková 2024-10-14 2024-10   LEWG Library Evolution
P3450R0 Extending is_within_lifetime Barry Revzin 2024-10-14 2024-10   LEWG Library Evolution
P3451R0 A Suggestion for Reflection Access Control Barry Revzin 2024-10-14 2024-10   EWG Evolution
P3454R0 Revising Atomic Max/Min Operations Michael Wong 2024-10-15 2024-10   SG1 Concurrency and Parallelism
P3455R0 SG14: Low Latency/Games/Embedded/Financial Trading virtual Meeting Minutes 2024/6/12-2024/10/9 Michael Wong 2024-10-14 2024-10   SG14 Low Latency
P3456R0 system_scheduler on Win32, Darwin and Linux Gor Nishanov 2024-10-15 2024-10   SG1 Concurrency and Parallelism,LEWG Library Evolution,LWG Library
P3457R0 SG19: Machine Learning virtual Meeting Minutes to 2024/06/13-2024/10/10 Michael Wong 2024-10-14 2024-10   SG19 Machine Learning
P3460R0 Contracts Implementors Report Eric Fiselier, Nina Dinka Ranns, Iain Sandoe 2024-10-16 2024-10   SG21 Contracts,EWG Evolution,CWG Core
P3465R0 Pursue P1179 as a Lifetime TS Herb Sutter 2024-10-15 2024-10   SG23 Safety and Security,EWG Evolution
P3466R0 (Re)affirm design principles for future C++ evolution Herb Sutter 2024-10-16 2024-10   EWG Evolution
P3467R0 2024-10 Library Evolution Polls Inbal Levi 2024-10-16 2024-10   LEWG Library Evolution
P3469R0 Virtual deducing this Mike Spertus 2024-10-16 2024-10   EWG Evolution
P3470R0 Interface-Unit-Only Module Library Support Daniel Ruoso 2024-10-15 2024-10   SG15 Tooling,EWG Evolution
P3471R0 Standard library hardening Konstantin Varlamov 2024-10-15 2024-10   SG23 Safety and Security,LEWG Library Evolution
P3472R0 Make fiber_context::can_resume() const Andrzej Krzemieński 2024-10-15 2024-10   LEWG Library Evolution
P3473R0 Splicing Should Respect Access Control Steve Downey 2024-10-16 2024-10   EWG Evolution
P3474R0 std::arguments Jeremy Rifkin 2024-10-15 2024-10   EWGI SG17: EWG Incubator,LEWGI SG18: LEWG Incubator
P3475R0 Defang and deprecate memory_order::consume Hans Boehm 2024-10-15 2024-10   SG1 Concurrency and Parallelism,EWG Evolution,LEWG Library Evolution,CWG Core,LWG Library
P3476R0 Slides for P2688R2 - Pattern Matching: `match` Expression Michael Park 2024-10-16 2024-10   EWG Evolution
P3477R0 There are exactly 8 bits in a byte JF Bastien 2024-10-16 2024-10   SG22 Compatibility,EWG Evolution,LEWG Library Evolution
P3478R0 Constification should not be part of the MVP John Spicer 2024-10-16 2024-10   SG21 Contracts,EWG Evolution
P3479R0 Enabling C pragma support in C++ Joshua Cranmer 2024-10-16 2024-10   SG6 Numerics,EWGI SG17: EWG Incubator,SG22 Compatibility
P3480R0 std::simd is a range Matthias Kretz 2024-10-16 2024-10   SG9 Ranges,LEWG Library Evolution
P3481R0 Summarizing std::execution::bulk() issues Lucian Radu Teodorescu 2024-10-16 2024-10   SG1 Concurrency and Parallelism,LEWG Library Evolution

Synchronization Primitives in C++20 -- Shivam Kunwar

El5Swmxm_400x400.jpgIn C++20, the standard library introduced new synchronization primitives: std::latch and std::barrier. These are the utilities designed to coordinate between concurrent threads.

Synchronization Primitives in C++20

by Shivam Kunwar

From the article:

What is a synchronization primitive?

In concurrent programming, synchronization primitives are the fundamental tools that help in managing the coordination, execution order, and data safety of multiple threads or processes that run concurrently.

Briefly said, they ensure that:

  • multiple threads don’t simultaneously execute some specific segment of code (a “critical section”)
  • the program and the data remain in a consistent state
  • deadlocks (where threads wait indefinitely for resources) and race conditions (where the outcome depends on the timing of accessing the shared data by a thread) are prevented or managed

There are multiple synchronization primitives in C++; for example, mutual exclusion, condition variables, atomic operations, locking mechanisms, etc.

In C++20, we have two additional synchronization primitives: latches and barriers.

Let’s discuss both of them.

std::latch

A std::latch is a synchronization primitive that permits a certain number of count_down operations (decrements) before allowing one or more threads to pass the wait point. A latch cannot be reused once its internal counter reaches zero.

How do we use a latch?

  • A std::latch object is created with an initial count.
  • Multiple threads can decrement this count using the count_down method.
  • Threads can call wait, which block until the internal count of the latch reaches zero.