<1>, C++ implements multi-thread synchronization processing: controlling the output sequence of ABC, outputting 10 groups, mutex+condition_variable

Table of Contents need: analyze: Some code implementation: 1. Operations implemented using only flag bits: 2. For greater security, the mutex lock code is added: 3. Use it with unique_lock to make the code safer Four: Use guard lock lock_guard to work with it 5. You can also use condition variables to process, which will […]

Linux kernel critical section, mutex, semaphore

1. Critical section: Access public resources or a piece of code through serialization of multi-threads. It is fast and suitable for controlling data access. 2. Mutex: Designed to coordinate individual access to a shared resource. 3. Semaphore: Designed to control a resource with a limited number of users. Critical Section A simple way to ensure […]

FreeRTOS mutual exclusion semaphore (mutex lock)

1. Mutually exclusive semaphore A mutually exclusive semaphore is actually a binary semaphore with priority inheritance, which is mostly used for mutually exclusive access to shared resources between different tasks. 2. Mutual exclusion semaphore reduces the impact of priority flipping When a mutex semaphore is being used by task L, and a task H also […]

Thread synchronization – mutex unlock, unlock

Similar to the locking and unlocking of inter-process communication semaphores. After the mutex is locked, any other thread that attempts to lock the mutex here will be blocked until the current thread releases the mutex lock. If multiple threads are blocked when the mutex is released, all threads blocked on the mutex will become runnable. […]

Linux–Threads–Mutex lock

1. Mutex a) A mutex is essentially a lock. Generally, defining a mutex in the main thread means defining a lock. Then operate this lock on the thread according to our needs. b) If all threads are locked, the threads will fight for memory space. Whoever gets it first will run first. Until the thread […]

Comparison of processes and threads, GIL global interpreter lock, mutex lock, thread queue, use of process pool and thread pool, multi-thread crawling of web pages, coroutine theory, coroutine to achieve high concurrency

Comparison of processes and threads 1. The overhead of the process is much greater than the overhead of the thread. 2. Data between processes is isolated, but data between threads is not isolated. 3. Thread data between multiple processes is not shared —–> Let process communication (IPC) ——-> Threads under the process also communicate —-> […]

Python coroutine, GIL global interpreter, mutex lock, thread pool, Concurrent module

The process is the smallest unit of resource allocation, and the thread is the smallest unit of CPU scheduling. There is at least one thread in every process. Python’s support for concurrent programming (1) Multi-threading: Threading uses the principle that CPU and IO can be executed at the same time, so that the CPU will […]

Coroutines, GIL global interpreter, mutex locks, thread pools, Concurrent module

The process is the smallest unit of resource allocation, and the thread is the smallest unit of CPU scheduling. There is at least one thread in every process. Python’s support for concurrent programming (1) Multi-threading: Threading uses the principle that CPU and IO can be executed at the same time, so that the CPU will […]

[Linux] Thread safety issues ① – Explanation of the principle of mutex locks & how to use mutex locks to achieve mutual exclusion of resource access (with diagrams and code implementation)

Thread safety is mainly divided into two aspects, namely resource access mutual exclusion and thread synchronization (thread cooperation) In this blog, we mainly explain the aspect of resource access mutual exclusion. Table of Contents Why do we need to implement resource access mutual exclusion? The classic mechanism to implement resource access mutual exclusion (atomic access) […]