Entries by Rainer Grimm

A Lock-Free Stack: Atomic Smart Pointer

The easiest way to solve this memory leak issue from the last post is to use a std::shared_ptr. Atomic Smart Pointer There are two ways to apply atomic operations on a std::shared_ptr: In C++11, you can use the free atomic functions on std::shared_ptr. With C++20, you can use atomic smart pointers. C++11 Using atomic operations […]

A Lock-Free Stack: A Complete Implementation

My last lock-free stack implementation was incomplete. It only supported push operations. Let’s change this. The following paragraph about sequential consistency is optional. You can easily ignore it. Sequential Consistency In my examples, I use the default memory ordering: sequential consistency. The reason is simple. Sequential consistency provides the strongest guarantees of all memory ordering […]

My ALS Journey (20/n): Aids

Today, I would like to introduce all the important aids that allow me and Beatrix to get through the day >> My ALS Journey so far << Aids Caregivers Of course, caregivers are not aids, but they still belong on this list. I can now have 24/7 care. This care is an incredible help for […]

A Lock-Free Stack: A Simplified Implementation

Today, I continue my mini story about lock-free data structures. General Considerations From the outside, the caller’s responsibility (application) is to protect the data. From inside, the data structure is responsible for protecting itself. A data structure that protects itself so a data race cannot appear is called thread-safe. First, what general considerations must you […]

Deferred Reclamation in C++26: Read-Copy Update and Hazard Pointers

Before I dive into lock-free programming, there’s a little bit of theory necessary. A common problem in concurrency is the so-called ABA problem. That means you read a variable twice, which returns the same value each time, A. Therefore, you conclude that nothing changed in between. But you forgot the B. Let me first use […]

std::format Extension

Displaying the address of an arbitrary pointer in C++ 20 fails but succeeds with C++26. C++20 Only void, const void, and std::nullptr_t pointer types are valid. If you want to display the address of an arbitrary pointer, you must cast it to (const) void*. // formatPointer20.cpp #include <format> #include <iostream> #include <string> int main() { […]

C++26 Library: string and string_view Processing

C++26 offers many small improvements around strings and string_views. First of all: What is a string_view? std::string_view A std::string_view is a non-owning reference to a string. It represents a view of a sequence of characters. This sequence of characters can be a C++ string or a C-string. In a typical way, C++17 offers four type […]

My ALS Journey (19/n): The Never Ending Story

Today, I present a sad story, and I can only take it by humor. >> My ALS Journey so far << My Electrical Wheelchair I need an electric wheelchair badly. This wheelchair should also support standing and sleeping. With this wheelchair, I can move inside and outside my flat and visit friends, things I could […]