Bilibili C++ Interview: Differences Between Mutex and Spin Lock, and Their Use Cases

Bilibili C++ Interview: Differences Between Mutex and Spin Lock, and Their Use Cases

In multithreaded programming, synchronization mechanisms are essential for ensuring safe access to shared resources.Mutexes and Spin Locks, as the two most classic types of locks, are widely used in various systems and frameworks.This article will comprehensively analyze the differences between the two from the perspectives of underlying implementation principles, waiting strategy differences, performance overhead analysis, … Read more

Understanding Priority Inversion in FreeRTOS: What Is It and How to Solve It?

Understanding Priority Inversion in FreeRTOS: What Is It and How to Solve It?

Imagine a scenario in a busy office building waiting for an elevator: Low-Priority Person: A visitor in no hurry (low-priority task) enters the elevator and presses a button for a high floor. Medium-Priority Person: At this moment, a manager in a hurry for a meeting (medium-priority task) also enters the elevator. High-Priority Person: Suddenly, the … Read more

Resource Management in FreeRTOS

Resource Management in FreeRTOS

Resource Management Problem: When a task is using a resource and is preempted before it has finished using it, the resource may be left in an incomplete or corrupted state. If another task or interrupt tries to access this resource at that time, it can lead to data corruption or processing errors. That is why … Read more

FreeRTOS Semaphores Explained

FreeRTOS Semaphores Explained

Semaphores Cover generated by Nano Banana 🍌🍌🍌 Using<span><span>binary semaphores</span></span> allows deferring tasks (tasks with high processing load and time consumption) in an interrupt to be completed in a processing (synchronization) task, ensuring that ISR() executes quickly. If the task in the interrupt is very urgent, it can be set to the highest priority, allowing the … Read more

Embedded Linux: Why Is Thread Synchronization Necessary?

Embedded Linux: Why Is Thread Synchronization Necessary?

Click the aboveblue text to follow us The core purpose of thread synchronization is to ensure that multiple threads can operate on shared resources in an expected manner, preventing data inconsistency issues. Shared resources refer to variables or data structures that multiple threads may read or modify simultaneously. For example, if there is a global … 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

Resource Management in FreeRTOS

Resource Management in FreeRTOS

Scan to FollowLearn Embedded Together, learn and grow together The FreeRTOS introductory series aims to help beginners quickly get started and master the basic principles and usage of FreeRTOS while organizing knowledge. FreeRTOS Quick Start – Exploring the System FreeRTOS Official Chinese Website is Now Live FreeRTOS Coding Standards and Data Types FreeRTOS Quick Start … Read more

FreeRTOS Queue Module (Part 2)

FreeRTOS Queue Module (Part 2)

The Queue in real-time operating systems (RTOS) such as FreeRTOS is a very important communication mechanism, mainly used for 1. Inter-Process Communication (IPC) and data transfer between tasks and interrupts.2. It can perform task synchronization and resource management. General queues can protect and utilize resources by implementing semaphores and mutexes.This article, as the second part … Read more

Priority Inversion Problem in FreeRTOS

Priority Inversion Problem in FreeRTOS

Priority inversion in FreeRTOS occurs when a high-priority task is blocked while waiting for resources (such as a mutex) held by a low-priority task, allowing a medium-priority task to execute in the meantime, which leads to scheduling anomalies where the high-priority task cannot run in a timely manner. Scenario Example: Task Priorities: There are three … Read more

Learning FreeRTOS: Mutex Semaphores

Learning FreeRTOS: Mutex Semaphores

Scan to followLearn Embedded Together, learn and grow together A mutex semaphore (Mutex, short for Mutual Exclusion) is a special type of binary semaphore in FreeRTOS, specifically designed for implementing mutual access to resources. Compared to ordinary semaphores, mutex semaphores have the following key characteristics: Ownership Concept: Only the task that takes the mutex can … Read more