C- Implement spin lock using atomic variables

Spin lock Spinlock is a low-cost lock commonly used in multi-thread programming. Its characteristic is that when a thread tries to acquire a lock and the lock is already occupied by other threads, the thread will be in a continuous busy wait (busy-wait). ) state until it can acquire the lock. This method avoids the […]

c++ atomic variable-Memory fence

Excerpted from: https://github.com/apache/brpc/blob/master/docs/cn/atomic_instructions.md#cacheline English version We all know that locks are commonly used in multi-core programming to prevent race conditions from occurring when multiple threads modify the same data. When locks become a performance bottleneck, we always want to try to bypass it, and inevitably come into contact with atomic instructions. But in practice, it […]

3. AtomicInteger for atomic operations

1. Preface Starting from this section, we will officially introduce you to the Java concurrency tool class. Today we will introduce to you the atomic operation AtomicInteger. This tool is located in the java.util.concurrent.atomic package. This section first explains what atomic operations are, and then introduces the most basic usage of the AtomicInteger tool class. […]

[C/C++ Multithreaded Programming] An in-depth discussion of double check locks and atomic operations

Directory title 1. Introduction 1.1 The Importance of Multi-threaded Programming in C++ 1.2 Challenges of Singleton Mode 2. Singleton Pattern and Double-Checked Locking 2.1. What is the Singleton Pattern? (What is the Singleton Pattern?) 2.2. How Double-Checked Locking Works 2.2.1. First inspection 2.2.2. Lock 2.2.3. Second inspection 2.3. Challenges with Double-Checked Locking (Challenges with Double-Checked […]

20 | Memory Models and Atomic: Understanding the Complexity of Concurrency

In the last lecture, we discussed some basic concepts of concurrent programming. Today we will discuss a slightly convoluted issue, the memory model and atomic weights in C++. Execution order issues in C++98 In the C++98 era, developers already understood the concept of threads, but the C++ standard did not mention threads at all. In […]

Punctual Atomic Embedded Linux Driver Development-Linux Kernel Startup Process

In the last note, I learned about the top-level Makefile of the Linux kernel. Now let’s look at the general startup process of the Linux kernel.The startup process of the Linux kernel The startup process is much more complicated than uboot and involves more content, so this chapter will give a general understanding of the […]

(2) Punctual Atomic STM32MP135 transplantation – TF-A transplantation

Table of Contents 1. Overview of TF-A 2. Compile the official code 2.1 Unzip the source code 2.2 Patching 2.3 Compilation preparation (1) Modify Makfile.sdk (2) Set environment variables (3) Compile 3. Transplantation 3.1 Copy official documents 3.2 Modify the power supply 3.3 Modify TF card and emmc 3.4 Add clk_hse 3.5 Delete other serial […]

Solving the atomicity problem in Java

2. Atomicity 2.1 volatile-problem Code Analysis: package com.itheima.myvolatile; ? public class Demo { public static void main(String[] args) { MyThread1 t1 = new MyThread1(); t1.setName(“Classmate Xiaolu”); t1.start(); ? MyThread2 t2 = new MyThread2(); t2.setName(“Classmate Xiaopi”); t2.start(); } } package com.itheima.myvolatile; ? public class Money { public static int money = 100000; } package com.itheima.myvolatile; ? […]