C++ Multithreading Magic Guide: Who Isn’t a Door with an Owner?

In the world of concurrency, sometimes what traps you is not others, but yourself. <span>recursive_mutex</span> <span>mutex</span> is the most basic and commonly used magic door. Regarding this category, C++ provides us with more options. Today, let’s take a look at <span>recursive_mutex</span>! 1. The Illusion of Deadlock 🪤 Imagine a task that rewards you with 100W💰 … Read more

The Truth Behind C++ Multithreading Vulnerabilities: 90% of Developers Are Unaware!

The Truth Behind C++ Multithreading Vulnerabilities: 90% of Developers Are Unaware!

C++ multithreading programming has always been a highly technical topic. It can bring significant performance improvements, but improper handling of details can lead to serious issues. With the popularity of multi-core processors, many developers choose to introduce multithreading to optimize program performance when facing compute-intensive tasks. However, C++ multithreading programming is not as simple as … Read more

Linux C++ Programming: A Detailed Tutorial on Using Shell + GDB to Diagnose Deadlocks

Linux C++ Programming: A Detailed Tutorial on Using Shell + GDB to Diagnose Deadlocks

1. Introduction In the process of writing projects, multithreading is often involved. Programming multithreaded applications usually involves issues of thread safety, which is why mutexes are often used to ensure thread safety. However, the use of mutexes can often lead to another problem: deadlocks. A deadlock, simply put, occurs when there are two shared resources, … Read more

Understanding C++ lock() and try_lock() Functions

Understanding C++ lock() and try_lock() Functions

1 Deadlock std::mutex mtM,mtN;int M = 0;int N = 0; void threadA() { std::lock_guard guardM(mtM); std::lock_guard guardN(mtN); M++; N–;} void threadB() { std::lock_guard guardN(mtN); std::lock_guard guardM(mtM); M–; N++;} This is a typical example that can lead to a deadlock. The classic two-phase locking issue is immediately apparent, but when more locks are involved, the problem … Read more

FreeRTOS ‘Phantom Deadlock’! System Randomly Freezes Driving the Entire Team Crazy, Finally Resolved with Priority Inheritance + SystemView

FreeRTOS 'Phantom Deadlock'! System Randomly Freezes Driving the Entire Team Crazy, Finally Resolved with Priority Inheritance + SystemView

Intelligent Terminal Control System, “Mysterious Freeze” After Running for Several Hours We developed an intelligent gateway based on STM32 + FreeRTOS for a client, featuring: Multithreaded tasks: sensor data collection, CAN communication, UI refresh, log writing Using mutexes to protect shared resources (such as LCD, Flash, serial port) Priority design was reasonable (or so we … Read more

Linux C++ Programming: Practical Debugging of Deadlocks with Shell and GDB

Linux C++ Programming: Practical Debugging of Deadlocks with Shell and GDB

When programming in C++ under the Linux environment, multithreading provides excellent concurrency capabilities, allowing programs to perform more efficiently when handling complex tasks. However, multithreaded programming is not without its challenges; deadlock issues lurk like hidden “killers,” potentially causing programs to become stuck. Once a deadlock occurs, the program is trapped in an unbreakable loop, … Read more

Guide to Avoiding Pitfalls in Embedded Development: A Comprehensive Analysis and Practical Solutions for I2C Bus Deadlocks

Guide to Avoiding Pitfalls in Embedded Development: A Comprehensive Analysis and Practical Solutions for I2C Bus Deadlocks

1. Introduction: When the “Two Wires” Suddenly “Stop Working“ In the daily work of embedded engineers, the I2C bus, with its two-wire communication feature, is a prime example of “minimalist aesthetics“. However, this seemingly simple two-wire system can suddenly fall into a “deadlock“—the clock line (SCL) stubbornly remains high, while the data line (SDA) is … Read more

How to Detect and Resolve I2C Communication Deadlocks

How to Detect and Resolve I2C Communication Deadlocks

Click the aboveblue text to follow us The I2C bus, as a widely used communication protocol in embedded systems, has its stability and reliability directly affecting the overall performance of the system. An I2C deadlock refers to a situation where the bus is stuck and unable to continue communication, usually caused by a slave device … Read more

How To Fix And Prevent Buffered Streams Deadlock

How To Fix And Prevent Buffered Streams Deadlock

How To Fix And Prevent Buffered Streams Deadlock Rust has eliminated various stupid bugs and traps that are common in other languages, making it easier to develop and maintain our projects. Unfortunately, when it comes to common problems in asynchronous programming, Rust is not inherently as strong. In fact, asynchronous programming in Rust is much … Read more

Revisiting I2C: Hardware Issues and Deadlock Solutions

Revisiting I2C: Hardware Issues and Deadlock Solutions

Welcome FPGA engineers to join the official WeChat technical group. ClickBlue TextFollow us at FPGA Home – the largest FPGA engineer community in China Generally, there are no issues with soldering I2C devices; following the device manual step by step usually leads to success. However, if such a simple thing fails to yield the desired … Read more