Exploring Static Variables in C++11 Lazy Singleton Pattern

Exploring Static Variables in C++11 Lazy Singleton Pattern

The singleton pattern in C++11 is one of the best practices we are familiar with. It utilizes the characteristics of static variables to safely implement lazy initialization, thread safety, and automatic memory management with very concise code. The implementation of the lazy singleton pattern in C++11 is roughly as follows: #include <iostream> class Singleton { … Read more

Comparison of Features Across C++ Versions from C++98 to C++23

Comparison of Features Across C++ Versions from C++98 to C++23

Core Feature List of Major C++ Versions (Only the most critical changes in the standard are listed for quick reference): C++98 / C++03 (C++98 is the first ISO standard, C++03 is a technical revision, essentially the same) • Standard Template Library (STL): vector, list, map, algorithm, etc. • Exception handling <span>try / catch</span> • Namespaces … Read more

C++ Learning Manual – New Features 46 – Lambda Expressions

C++ Learning Manual - New Features 46 - Lambda Expressions

In the world of C++ programming, we have always pursued more concise, flexible, and powerful expressions. The introduction of Lambda expressions is one of the significant gifts brought to us by C++11. It has fundamentally changed the way we define and use function objects, making the code more elegant and efficient. What are Lambda Expressions? … Read more

C++ Learning Manual – New Features: Range-based For Loop

C++ Learning Manual - New Features: Range-based For Loop

The C++11 standard introduced a series of modern features, among which the range-based for loop is undoubtedly one of the most popular and easiest to grasp. It greatly simplifies the syntax for iterating over elements in containers (such as arrays, vectors, lists, etc.), making the code clearer, more concise, and safer. This article will delve … Read more

CMake: Set Language Standard (Part One)

CMake: Set Language Standard (Part One)

Introduction: Programming languages have different standards, and enabling a new standard is achieved by setting appropriate compiler flags. First, let’s understand the relevant features of C++ 11. For information on setting language features, please refer to the previous or earlier articles regarding CMakeLists.txt, which also cover this topic! ✦ C++ Standard History✦ In 1998, the … Read more

82 Pages Modern C++ Tutorial: Quickly Get Started with C++ 11/14/17/20

82 Pages Modern C++ Tutorial: Quickly Get Started with C++ 11/14/17/20

Machine Heart Report Editor: Chen Ping C++ is an ancient yet novel language. What new features does modern C++ have? This book will take you through it. Since its invention, C++ has undergone multiple revisions, each adding new features and making some modifications. Looking back at the history of C++, it took more than a … Read more

Implementing a Read-Write Spinlock in C++11 – Part 3 (Sequential Lock)

Implementing a Read-Write Spinlock in C++11 - Part 3 (Sequential Lock)

The previous article introduced a read-write lock implementation scheme where writers are not starved by readers who come later, ensuring fairness for writers competing for the lock with readers. This article introduces a special type of read-write spinlock that guarantees the highest priority for write operations. Specifically, when there is only one writer, meaning there … Read more

Introduction to Multithreading in C++11 (Part 1)

Introduction to Multithreading in C++11 (Part 1)

Introduction This series is written because I found my programming skills to be lacking, so I wanted to create a blog to help myself review. I hope it can help everyone (and not mislead too much). If you have any questions, feel free to point them out in the comments. The environment for this article … Read more

Multithreaded Programming in Embedded Linux

Multithreaded Programming in Embedded Linux

Multithreaded Programming in Embedded Linux 1. What is a Thread? 1.1 Essence of Threads A thread is the smallest execution unit scheduled by the operating system, sharing the resources of a process (memory, files, etc.), but possessing independent: Stack space (for storing local variables) Register state (program counter, etc.) Thread ID and priority 1.2 Comparison … Read more

Quick Mastery of New C++ Features: High-Performance Thread Pool Design and Implementation in C++11

Quick Mastery of New C++ Features: High-Performance Thread Pool Design and Implementation in C++11

Overview This is a high-performance thread pool implemented based on the C++11 standard, featuring the following characteristics: Supports any function as a task: Can execute regular functions, member functions, lambda expressions, etc. Supports obtaining return values: Asynchronously obtain task execution results through the std::future mechanism Type-safe: Ensures type safety using C++11 template deduction Efficient synchronization: … Read more