In-Depth Analysis of Linux VFS Atomic Operation Functions: Key Technologies for Building Reliable File Systems

In-Depth Analysis of Linux VFS Atomic Operation Functions: Key Technologies for Building Reliable File Systems

In the Linux system, the virtual file system (VFS) serves as an abstraction layer for file systems, providing a unified file operation interface for upper-level applications. The previous article detailed the core member interface functions of Linux VFS, helping to understand the underlying implementation of file systems. The atomic operation mechanism implemented at the VFS … Read more

Practical C++ Atomic Operations: Techniques for Implementing Lock-Free Data Structures

In high-concurrency scenarios, have you encountered the dilemma of using mutexes to protect shared data, only to face performance bottlenecks due to frequent thread blocking? For instance, in high-frequency trading systems for order processing or server request queues, the overhead of context switching caused by lock contention often becomes the “last straw” that breaks performance. … Read more

Embedded Reading Notes – 3: Detailed Explanation of Linux Device Driver Development

Concurrency Control in Linux Device Drivers (Part 1) Note: The content of this article is excerpted from “Detailed Explanation of Linux Device Driver Development – Based on the Latest Linux 4.0 Kernel”. This series will record the key points of knowledge focused on while reading the book. Interested readers are recommended to read the original … Read more

C++ Multithreading Magic Guide: The Atomic Button Machine

⚛️ std::atomic — The Mysterious Power of the Atomic Button Machine ⚙️ <span>std::atomic</span> is a concurrent primitive provided by C++, allowing you to operate on a variable in a multithreaded environment without needing locks to ensure consistency. Its core goal: “To allow multiple threads to read and write to a variable simultaneously without conflicts, without … Read more

In-Depth Understanding of C++ Happens-Before: A Must for Advanced Concurrent Programmers

1. Introduction: Why is Happens-Before Necessary? In multithreaded programs, “statement order” ≠ “execution order”.Modern CPUs and compilers can reorder instructions as long as the results in a single thread remain unchanged, allowing for free optimization.However, in concurrent scenarios, this can lead to serious issues: bool ready = false;int data = 0; void writer() { data … Read more

A Concise Guide to C++ std::atomic

When it comes to thread safety in multithreaded programming, many people’s first reaction islocks (mutex)🔒. For example, with a counter, some threads are incrementing while others are decrementing. To prevent multiple threads from operating simultaneously, we can use locks for protection. But is using a lock for a counter a bit too costly? Is there … Read more

Exploring Lock-Free Queues in C++: Various Implementations and Performance Comparisons

Exploring Lock-Free Queues in C++: Various Implementations and Performance Comparisons

Implementing a lock-free queue in C++ is a complex task because lock-free programming involves intricate memory operations and synchronization mechanisms, requiring a deep understanding of concurrent programming and hardware-level atomic operations. The advantage of lock-free queues is that they can provide better performance in high-concurrency scenarios, as they avoid the thread contention and context-switching overhead … Read more

Understanding C++ Memory Model

Understanding C++ Memory Model

↓Recommended to follow↓ This article is a sister piece to “C++ Concurrency Programming”. It will focus on the memory model introduced by the C++11 standard. Introduction In the article “C++ Concurrency Programming”, we have already introduced the new APIs in concurrent programming from C++11 to C++17. With the knowledge from that article, you should be … Read more

Low-Level Implementation of Atomic Operations in Linux Kernel (armv8-aarch64)

Low-Level Implementation of Atomic Operations in Linux Kernel (armv8-aarch64)

Typically, a line of code like a = a + 1 in our code translates to three assembly instructions: ldr x0, &amp;a add x0,x0,#1 str x0,&amp;a That means (1) reading variable a from memory into register X0 (2) adding 1 to register X0 (3) writing X0 back to memory a Since there are three instructions, … 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