Multithreading – Thread Pool

1. What is a thread pool Although the creation of threads is more lightweight than processes, the overhead is still not negligible in the case of frequent creation and destruction, so thread pools are introduced. Thread pool is a form of multi-thread processing. It creates some threads in advance, stores them, and can be used […]

Multithreading—understanding threads

Article directory What is a process? How to manage processes? Know PCB Understand the process of process scheduling virtual address space What is a thread? Process VS Thread Properties and methods of Thread class Properties of Thread class Thread class methods Construction method Ordinary method Thread status What is a process? Process, also called “task”, […]

Multithreading—Lock strategy and CAS

Article directory Common lock strategies Optimistic locking VS pessimistic locking Read-write lock VS ordinary mutex lock Heavyweight lock VS lightweight lock Spin lock VS suspend wait lock Fair lock VS unfair lock Reentrant lock VS non-reentrant lock CAS What is CAS? Use of CAS ABA issues with CAS deadlock Common lock strategies Optimistic locking VS […]

The principle and implementation of Python multithreading

Python multi-threading principles and practice Purpose: (1) Understand the principle of python thread execution (2) Master multi-thread programming and thread synchronization (3) Understand the use of thread pools 1 Basic concepts of threads 1.1 What is a thread? Thread refers to an execution unit within a process and is also a schedulable entity within the […]

JavaEECAS — Multithreading (7)

CAS 1. What is CAS 2. CAS pseudocode 3. How is CAS implemented? 4. Application of CAS 4.1 Implementing atomic classes 4.2 Implement spin lock 5. ABA issues with CAS 1. What is CAS CAS: Full name Compare and swap, literal meaning: “Compare and swap” Able to compare and exchange the value in a certain […]

C++11 – Multithreading

Table of Contents 1. A brief introduction to the thread class 2. Thread function parameters 3. Atomic operation library (atomic) 4.lock_guard and unique_lock 1.lock_guard 2.unique_lock 5. Condition variables 1. A brief introduction to the thread class Before C++11, multi-threading issues were all related to the platform. For example, windows and linux each had their own […]

Java: Multithreading (2)

Methods related to thread life cycle: When sleep calls the sleep method, it will enter the timing waiting state. When the waiting time is up, it will enter the ready state. Yield Calling the yield method will allow other threads to execute, but it does not ensure that it is actually yielded. Rarely used, official […]

Linux – multithreading

Table of Contents 1. What is a thread? 2. The main difference between processes and threads 3. Reasons for using threads 4. Thread related functions 4.1 Creation of threads 4.2 Thread exit 4.3 Thread waiting 4.4 The ID of the thread itself 4.5 Sample code 5. Mutex lock 5.1 Related functions (brief description) 5.2 Deadlock […]

Multithreading – Locking Strategy & CAS

Common lock strategies The lock strategies mentioned here are not limited to Java, C++, Python, databases, operating systems… As long as locks are involved, the following lock strategies can be applied Optimistic locking vs pessimistic locking The implementer of the lock predicts whether the probability of the next lock conflict (lock competition, two threads lock […]

Multithreading (thread synchronization)

Introduction Today there were two children. Each took their own fifty cents and went to the supermarket to buy lollipops. When I saw the price, I was stunned! A lollipop costs one yuan, and neither of us can buy a lollipop to eat. At this time, one of the children said to the other child: […]