[Reprint] C # Use Interlocked for atomic operations,
Source article: Wang Xu blog» C # Use Interlocked for atomic operations
What is an atomic operation?
Atom is intended to be "the smallest particle that cannot be further divided", while atomic operation is "one or a series of operations that cannot be interrupted ".
2iSome years ago I started work on my first CUDA implementation of the Multiparticle collision Dynamics (MPC) algorithm, a Particle-in-cell code used to simulate hydrodynamic interactions between solvents and solutes. As part of the This algorithm, a number of particle parameters is summed to calculate certain cell parameters. This is in the days of the Tesla GPU architecture (such as GT200 GPUs, Compute Capability 1.x), which had poor atomic ope Rati
Atomic operation (1)-Atomic operation with Assembly "The most lightweight locks", often also called "atomic operations", are quoted because they are not atomic at the assembly level and are done with multiple instructions, mostly using the CPU-supported assembly instructions.In some architectures that are outdated CPU
[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
Atomic locks are a feature of multi-threaded programming. However, in normal software writing, there are not many atomic locks. There are many reasons for this. I think there are two main reasons. First, there are few introductions on
The Java.util.concurrent package (J.U.C) after Java5 is the work of the world-class concurrent Master Doug Lea, which mainly implements
The corresponding atomic class of Integer/long in atomic package is mainly based on CAS;
Some of the same steps, including Lock,countdownlatch,semaphore,futuretask, are based on the Abstractqueuedsynchronizer class;
About the executors class of thread exec
Java. util. Concurrent. Atomic. Atomic * atomic class and volatile keyword are two common methods in Java to process data shared read/write under multiple threads. The two seem to be the same, but they are quite different in practical applications.
The volatile keyword is a write lock implemented by local code. It only ensures that a thread is writing data. To sp
CAS atomic Operations--compare Set, or Compare Swap, now almost all CPU instructions support CAS atomic operations, X86 corresponding to CMPXCHG assembly instructions.You should remember the concept of "atomic manipulation" inside the operating system, where an operation is atomic (
Faster Atomic class: Longadder
Everyone to the basic realization mechanism of the atomicinteger should be more understanding, they are in a dead loop, and constantly try to modify the target value, know the success of the modification, if the competition is not fierce, then the probability of successful modification is very high, otherwise, the probability of modification failure is very high, in a large number of changes failed, These
In this section, we begin to discuss array atomic operations and some other atomic operations.Atomicintegerarray/atomiclongarray/atomicreferencearray 's API is similar, select a representative atomicintegerarray to describe these issues.int get (int i)Gets i The current value of the position. Obviously, because this is an array operation, there is an index cross-boundary problem (Indexoutofboundsexception e
Atomic and nonatomic are used to determine whether the compiler-generated getter and setter are atomic operations.
Atomic
When setting the @property property of a member variable, the default is atomic, which provides multithreading security.
In a multithreaded environment, at
The various "Tasks" in the Linux kernel can see the kernel address space, so they also need synchronization and mutual exclusion. The synchronization/Mutex methods supported by the Linux kernel include:
Technology
Function
Scope of Action
Per-CPU variable
Copy a piece of data for each CPU
All CPUs
Atomic operation
Atomic read-Modify-write a counter to
time to obtain a certain resource. if they remain in the waiting status, they will lead to a "live lock ", that is to say, it wastes both memory and CPU time, which is more terrible than the deadlock in the following sections. How can we use the powerful CPU time to do more? The following mode is introduced.
1.3 primitive kernel mode
This mode is different from the user mode. It is provided by the Windows system and uses kernel functions in the operating system. Therefore, it can block threads
What is atomic operation?
Atom (Atom) is meant to be "the smallest particle that cannot be further divided", whereas atomic manipulation (atomic operation) means "one or a series of operations that cannot be interrupted". When there are multiple threads in C # that operate on a variable at the same time, we should use atomic
Before talking about the process context, the interrupt context, and the atomic context, it is necessary to discuss the following two concepts:A--contextThe context is translated from English ContexT, which refers to an environment . in relation to the process, it is the environment when the process executes; In particular, variables and data, including all register variables, process open files, memory information, and so on.B--AtomicAtom (Atom) is
1. Non-blocking algorithm
Non-blocking algorithms belong to concurrent algorithms that can safely derive their threads, not by locking, but through low-level atomic hardware native forms-such as comparisons and exchanges. The design and implementation of non-blocking algorithms is extremely difficult, but they provide better throughput and provide better defenses against survival problems such as deadlocks and priority inversion. Use the underlying a
Atomic and nonatomic are used to determine whether the compiler-generated getter and setter are atomic operations. AtomicWhen you set the @property property of a member variable, the default is atomic, which provides multithreading security.in a multithreaded environment, atomic operations are necessary, otherwise they
This article from: http://blog.163.com/hbu_lijian/blog/static/126129153201261722410353/
Kernel synchronization measures (for Linux kernel)
To avoid concurrency and prevent competition. The kernel provides a set of Synchronization Methods to protect shared data. Our focus is not to introduce the detailed usage of these methods, but to emphasize the difference between these methods and them.The synchronization mechanism used in Linux has been continuously improved since 2.0 to 2.6. From the initia
I. Introduction
In OpenMP, the thread synchronization mechanism includes the mutex lock synchronization mechanism and event synchronization mechanism. This section describes the atomic method in the mutex lock synchronization mechanism.
Ii. mutex lock synchronization Concept
The concept of mutex synchronization is similar to the criticalsection in windows, the mutex in Windows and Linux, and the semtake semgive in VxWorks (the semaphore is full durin
OC has nonatomic and atomic two choices when defining attributesAtomic: Atomic attribute, locking for setter method (default is Atomic)Nonatomic: Non-atomic attribute, does not lock the setter methodAtomic Plus Lock principle1 @property (assign, atomic) int age;2 3-(void) Se
This is a creation in
Article, where the information may have evolved or changed.
This article explains the common operations of sync.atomic in Golang
The atomic operation provided by atomic ensures that only one goroutine can operate on the variable at any one time, and the use of atomic avoids a large number of lock operations in the program.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.