Concurrent programming has not been sorted out yet, let’s post about mutexes first (refer to Li Wenzhou’s blog) Mutex In Go language, the Mutex type provided in the sync package is used to implement mutual exclusion locks. The bottom layer of this type is a structure, and the structure is a value type. If it […]
Tag: mutex
Related usage scenarios of mutex in ATF
bakery lock Let’s take a look at the appearance of this bread in ATF. Scenario 1: Runtime service initialization BL31 is responsible for initializing runtime services. One of them is PSCI. As part of PSCI initialization, BL31 detects the system topology. It also initializes the data structures implementing the state machines used to track the […]
Java uses mutex to solve cache breakdown problem
1. Cache breakdown principle The cache breakdown problem is also called the hotspot key problem, which means that a key with high concurrent access and complex cache business suddenly fails, and countless access requests bring a huge impact to the database in an instant. 2. The principle of mutual exclusion lock The mutual exclusion lock […]
One article clearly explains the principles and usage of C language multithreading, signals, mutexes, and condition variables (including cases)
Introduction Thread (Thread): A thread is a concurrent execution flow within a program, also known as a lightweight process. Unlike processes, threads share the same memory space, so data and communication can be shared more easily. Threads can be created, destroyed, synchronized and communicated through the pthread library. Signal (Signal): Signal is an inter-process communication […]
Thread synchronization mutex named semaphore, unnamed semaphore
1. Thread mutual exclusion mode 1. What is a synchronous mutual exclusion? Why deal with synchronized mutexes? Synchronization mutual exclusion is to make threads process tasks in a sequential order, in order to prevent thread resources from being preempted. 2. What are the ways to deal with synchronous mutual exclusion? Semaphore -> Process (shared memory […]
C++11 threads, mutexes and condition variables
Article directory foreword 1. Create the first thread 2. The life cycle, waiting and separation of thread objects 3. Multiple ways to create threads 4. Mutex 4.1 Exclusive mutex std::mutex 4.2 Recursive exclusive mutex recursive_mutex 4.3 Mutex std::timed_mutex and std::recursive_timed_mutex with timeout 4.4 std::lock_guard and std::unique_lock 5. Use of call_once/once_flag 6. Condition variables Foreword Before […]
Thread synchronization, mutex, deadlock, read-write lock
A case of using multithreading to realize ticket purchase. There are 3 windows, a total of 100 tickets Version 1: The problem of thread synchronization is not considered, and there will be situations where multiple windows buy the same ticket */ #include <stdio.h> #include <pthread.h> #include <unistd.h> // Global variables, all threads share this resource. […]
Thread synchronization mutual exclusion mutex, read-write lock, condition variable
1. Basic concepts Mutex and synchronization are the most basic logical concepts: Mutual exclusion refers to controlling two processes so that they are mutually exclusive and do not run at the same time. Synchronization refers to controlling two progresses so that they come first and then come first, and the order is controllable. 2. Mutex […]
C++ high performance: std multithreading thread, mutex, condition_variable future
mutex std::mutex std::mutex mtx;,mtx.lock();,mtx.unlock(); // https://cplusplus.com/reference/mutex/mutex/ // mutex example #include <iostream> // std::cout #include <thread> // std::thread #include <mutex> // std::mutex std::mutex mtx; // mutex for critical section void print_block (int n, char c) {<!– –> // critical section (exclusive access to std::cout signaled by locking mtx): mtx. lock(); for (int i=0; i<n; + + […]
C++ multi-thread data sharing problem, mutex, deadlock and solution
1. The problem of data sharing between threads Question: You share an apartment with your friend, and there is only one kitchen and one bathroom in the apartment. When your friend is in the bathroom, you will not be able to use it; or if two people book a ticket on the ticketing website, with […]