Semaphore Overview (C++)

Semaphore Overview (C++)

Semaphore is a very important synchronization mechanism in concurrent programming (multithreading/multiprocessing), used to control access to shared resources by multiple threads or processes, preventing issues such as race conditions, data inconsistency, or deadlocks. 1. What is a Semaphore? ✅ Definition: A semaphore is a synchronization tool used to control access to shared resources by multiple … Read more

Scheduler Fairness and Real-Time Performance: Golang vs Erlang

Scheduler Fairness and Real-Time Performance: Golang vs Erlang

Scheduler Fairness and Real-Time Performance: Golang vs Erlang Overview This codebase contains a comparative analysis of scheduling fairness and real-time performance between Golang and Erlang. Tests indicate that the performance of Golang’s goroutine scheduler is subpar — it is coarse, unfair, and lacks good real-time capabilities. In contrast, Erlang’s scheduler excels in both fairness and … Read more

Basics of Python Multithreading: From Thread to ThreadPoolExecutor

Basics of Python Multithreading: From Thread to ThreadPoolExecutor

1. What Can Multithreading Solve? First, we need to clarify a concept: Concurrency (并发) ≠ Parallelism (并行). Concurrency is “appearing to run simultaneously”. For example, when you listen to music while coding, your brain quickly switches between the two tasks, which is called concurrency. Parallelism is “actually running simultaneously”. This requires multiple CPU cores, just … Read more

Don’t Let These C++ Pitfalls Bury Your Code

Don't Let These C++ Pitfalls Bury Your Code

The flexibility and complexity of C++ lead to numerous “hidden traps”—issues that are often syntactically valid but can cause hard-to-debug runtime errors, performance degradation, or logical flaws. Here are the most common pitfalls encountered in engineering practice, covering core areas such as memory management, syntax features, STL usage, and concurrent programming, along with specific examples … Read more

Implementing a Read-Write Spinlock in C++11 – Part 2 (Memory Order)

Implementing a Read-Write Spinlock in C++11 - Part 2 (Memory Order)

When implementing locks, it is necessary to ensure the memory order semantics of the lock: generally, an acquire memory order is required when acquiring the lock, and a release memory order is required when releasing the lock. This acquire-release semantics guarantees that memory read and write operations in the critical section do not get reordered … Read more

Beware! Don’t Let These C++ Pitfalls Bury Your Code

Beware! Don't Let These C++ Pitfalls Bury Your Code

The flexibility and complexity of C++ coexist, leading to numerous “hidden traps”—these issues are often syntactically valid but can cause hard-to-debug runtime errors, performance degradation, or logical flaws. Below are the most common pitfalls encountered in engineering practice, covering core areas such as memory management, syntax features, STL usage, and concurrent programming, along with specific … Read more

Lock Mechanisms from Microcontrollers to Linux

Lock Mechanisms from Microcontrollers to Linux

In concurrent programming development, lock mechanisms are core technologies to ensure data consistency and thread safety. Whether in resource-constrained microcontroller environments or feature-rich Linux systems, lock mechanisms play a crucial role. Lock Mechanisms What is a Lock Mechanism? A lock mechanism is a synchronization primitive used to control access to shared resources by multiple execution … Read more

Concurrent Programming in Rust: A Detailed Explanation of Core Methods for Data Sharing Between Threads

Concurrent Programming in Rust: A Detailed Explanation of Core Methods for Data Sharing Between Threads

Concurrent Programming in Rust: A Detailed Explanation of Core Methods for Data Sharing Between Threads In modern computing, multithreaded programming is key to enhancing application performance and achieving high concurrency. However, data sharing between threads has always been a significant challenge in concurrent programming, fraught with pitfalls such as data races and deadlocks. The Rust … Read more

Introduction to C++: A Programming Tool from Low-Level Hardware to High-Level Abstraction

Introduction to C++: A Programming Tool from Low-Level Hardware to High-Level Abstraction

1. Introduction to C++ C++ is a statically typed, compiled, general-purpose, case-sensitive, and irregular programming language that supports procedural programming, object-oriented programming, and generic programming. C++ is considered a middle-level language, combining features of high-level and low-level languages, allowing for efficient low-level hardware operations while providing high-level abstraction and encapsulation mechanisms. 1. Development History C++ … Read more

Detailed Explanation of Thread Programming: From Basics to Embedded Practice

Detailed Explanation of Thread Programming: From Basics to Embedded Practice

1. Introduction: Why Do We Need Threads? In the previous two documents, we explored the concept of processes, address space, and inter-process communication mechanisms. While processes provide the foundation for multitasking programming, in certain scenarios, the process model can be too heavyweight. Imagine if an application needs to handle multiple concurrent tasks simultaneously; creating a … Read more