News

CppCon 2020 A Multi-threaded, Transaction-Based Locking Strategy for Containers--Bob Steagall

Registration is now open for CppCon 2021, which starts on October 24 and will be held both in person and online. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from our most recent in-person conference in 2019 and our online conference in 2020. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2021 to attend in person, online, or both!

A Multi-threaded, Transaction-Based Locking Strategy for Containers

by Bob Steagall

Summary of the talk:

With the concurrency tools available in the modern C++ standard library, it is easier than ever to create multi-threaded programs. When we write such applications, there are sometimes cases in which a container simply must be shared among multiple threads. Of course, sharing is trivial if the only operations on the container are reads. In the case where reads greatly outnumber writes, acceptable performance is often attainable with a reader/writer mutex type, like std::shared_mutex. But suppose that the number of writes is similar to, or even greater than, the number of reads -- how does one then perform simultaneous reads and writes on a single container?

One common usage pattern is that, for a given operation, sets of related records are read and updated together. In order to prevent data races and inconsistent views of the data, such sets must be locked together as a unit before any of them can actually be read or updated. Further, it is very easy to accidentally create deadlocks by choosing a seemingly correct locking order. In order to avoid these problems, we would like a locking algorithm that provides three important properties: atomicity, consistency, and isolation.

This talk will describe an algorithm, implemented in C++, that performs such locking based on the concept of strict timestamp ordering. Using only facilities from the C++17 standard library, it employs a straightforward approach to multi-threaded, transactional record locking that requires minimal spatial overhead and yet fulfils the requirements of atomicity, consistency, and isolation. We'll discuss the pros, cons, and limitations of the algorithm, and provide some performance measurements.

Empty Base Class Optimisation, no_unique_address and unique_ptr--Bartlomiej Filipek

Life made easier.

Empty Base Class Optimisation, no_unique_address and unique_ptr

by Bartlomiej Filipek

From the article:

C++20 added a couple of new attributes in the form of [[attrib_name]]. One of them - [[no_unique_address]] - can have surprising effects on the code! In this blog post, you’ll learn how to optimize your classes' layout and make some data members “disappear”. In most cases, it will be just one line of C++20 code.

Let’s go...

CppCon 2019 Time Travel: Applying Gradual Typing to Time Types with Clang's LibTooling--Hyrum Wright

Registration is now open for CppCon 2021, which starts on October 24 and will be held both in person and online. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from our most recent in-person conference in 2019 and our online conference in 2020. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2021 to attend in person, online, or both!

Time Travel: Applying Gradual Typing to Time Types with Clang's LibTooling

by Hyrum Wright

Summary of the talk:

Libraries for C++ are constantly evolving, with new APIs being added, old ones being deprecated and functionality continually changing. In past CppCon talks, I've described in abstract how Google manages this change by applying large-scale changes across our C++ codebase using clang's libTooling infrastructure.

In this talk, we'll put this previous work in practice by demonstrating how we use clang-tidy and clang's libTooling library to improve type safety of time types across Google's 250M lines of C++. Using tools currently open sourced as part of clang-tidy, we'll show how the underlying model of time types allow us to migrate from a collection of integers and floating point types to the much more strongly typed `absl::Time` and `absl::Duration` types representing time instants and intervals. Along the way, we'll discover how this process finds existing bugs and prevents new ones from creeping in.

This "gradual typing" technique is not limited to just Time types, and we'll explore how this can be used to improve pointer ownership deduction and other places where more constraining types eliminate classes of bugs.

How to Define Comparison Operators by Default in C++--Jonathan Boccara

Do you know?

How to Define Comparison Operators by Default in C++

by Jonathan Boccara

From the article:

Implementing comparison operators in C++ is easier said than done.

Indeed, for most types, if we could talk to the compiler we would say something like: “to order them, use a lexicographical order on their members”.

But when it comes to writing the corresponding code, things get more complicated.

However, a classical technique using std::tuple makes the code much more concise for comparison operators, and it should be used by default. (At least before C++20, as C++20 made comparison operators even easier to write).

Let’s see the technique involving std::tuple and then how the comparison operators situation evolves with C++20...

CppCon 2020 Back to Basics: Exceptions--Klaus Iglberger

Registration is now open for CppCon 2021, which starts on October 24 and will be held both in person and online. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from our most recent in-person conference in 2019 and our online conference in 2020. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2021 to attend in person, online, or both!

Back to Basics: Exceptions

by Klaus Iglberger

Summary of the talk:

Exceptions are the native error propagation mechanism in C++. If used properly, exceptions enable us to write simpler, more readable and more robust code. However, the path there can be tricky and unfortunately the exception mechanism isn't without flaws. This talk sheds somelight on the current issues with exceptions and why a large part of the C++ community isn't using them. It also gives guidelines and best practices on how to deal with exceptions and how touse them properly. It will go into detail about the exception safety guarantees, explains the tradeoffs between them, and demonstrates by example the individual steps necessary to reach them.

C++20 modules with GCC11--Niall Cooling

Will you start using them?

C++20 modules with GCC11

by Niall Cooling

From the article:

One of the headline changes of the C++20 standard is the inclusion of modules. Modules promise to significantly change the structure of C++ codebases and possibly signal headers’ ultimate demise (but probably not in my lifetime). It also opens the door to potentially have a unified build system and package manager, similar to Rust’s Cargo package manager; though I imaging standardising a unified build system would be one bloody battle.

Embrace Your Problem Domain With Strong Types! -- Richard Thomson

Utah C++ Programmers has released a new video.

Embrace Your Problem Domain With Strong Types!

by Richard Thomson

From the video description:

Every piece of software we write fits into some sort of specific problem domain. Programming isn't about writing programs! Programming is about solving problems. [...]

One area that is often overlooked when modeling our problem domain is coming up with abstractions for the most common and simple values used in our programs. "We need to store a telephone number for the customers in our inventory system." "OK, let's use a std::string, that ought to do it."

That's certainly an expedient solution, but is it a good solution? [...]

This month, Richard Thomson will give us a guided tour on how we can write domain specific types in C++. We'll take a look at facilities provided directly by the language to roll our own types and we'll look at some library solutions that save us from writing lots of boiler plate.

ReSharper C++ 2021.2 brings type conversion hints, immutability inspections, ... -- Elvira Mustafina

ReSharper C++ 2021.2 is released!

ReSharper C++ 2021.2: Type Conversion Hints, Immutability Inspections, Inline Function

by Elvira Mustafina

From the article:

ReSharper C++ 2021.2 is now available for download! It brings new inlay hints to help you spot implicit type conversions, the Inline Function refactoring, and updates to Unreal Engine support. New modernizing inspections assist you with updating your code to modern C++, and improved immutability analyses keep your code more readable and correct.

  • New inlay hints that show implicit type conversions.
  • Inline Function refactoring.
  • Immutability inspections (and now Constants and immutability section of the C++ Core Guidelines is fully covered!).
  • More inspections to help you modernize your code.
  • Support for Unreal Engine 5 and other enhancements for game developers on UE.
  • cppreference.com links in the Quick Documentation pop-ups.
  • The bundled Clang-Tidy has been updated to Clang 12, adding new checks from the latest LLVM release.

CppCon 2019 A Critical Look at the Coding Standards Landscape--Michael Price

Registration is now open for CppCon 2021, which starts on October 24 and will be held both in person and online. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from our most recent in-person conference in 2019 and our online conference in 2020. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2021 to attend in person, online, or both!

A Critical Look at the Coding Standards Landscape

by Michael Price

Summary of the talk:

The C and C++ programming languages are rife with spiky pits, hairpin curves, and loaded footguns, leading industries working with critical systems to embrace strict standards that aim to reduce the amount of damage that can be done with the awesome powers available to them when using these languages.

This session will briefly review what sorts of standards exist in the public today, leading into a serious critique of the more foolish and user-unfriendly aspects of these standards, and finally closing with an optimistic view of “the good parts” of the same.