Depending on the type of data being modified, the atomic action classes in the JUC package can be grouped into 4 classes.
1. Basic types: Atomicinteger, Atomiclong, Atomicboolean;
2. Array type: Atomicintegerarray, Atomiclongarray, Atomicreferencearray;
3. Reference type: Atomicreference, atomicstampedrerence, atomicmarkablereference;
4. Object's property modification type: Atomicintegerfieldupdater, Atomiclongfieldupdater, Atomicreferencefieldupd
Typedef struct {int counter;} atomic_t; # ifdef config_64bittypedef struct {long counter;} atomic64_t; # endif
The Linux kernel uses the Special Data Type atomic_t instead of the integer type that uses the C language directly, which is due to the following reasons:
(1) The atomic_t function only accepts the atomic_t type.
(2) Using the atomic_t type can avoid Compiler Optimization. Atomic operations are very important to using the correct memory ad
When multiple processes open the same file to write logs, the o_append parameter is specified during open. UNIX can ensure that this operation is atomic,ProgramNo need to lock yourself
/* Log1.c */ # Include # Include String . H> # Include # Include Int Max = 300 ; Int Main (){ Int I; Int FD; FD = Open ( " 1. Log " , O_wronly | O_append ); For (I = 0 ; I ){ Char MSG [ 100 ]; Sprintf (MSG, " Log1: Message % d... \ n " , I); slee
Type _ sync_fetch_and_add (type * PTR, type value ,...)Type _ sync_fetch_and_sub (type * PTR, type value ,...)Type _ sync_fetch_and_or (type * PTR, type value ,...)Type _ sync_fetch_and_and (type * PTR, type value ,...)Type _ sync_fetch_and_xor (type * PTR, type value ,...)Type _ sync_fetch_and_nand (type * PTR, type value ,...)These functions perform operations on the memory address pointed to by PTR and return the value before the operation.Type _ sync_add_and_fetch (type * PTR, type value ,..
is not a specific technical problem, just come here to ask you a solution.
As follows: If there is a record in the database, the fields are as follows:
ID file
1 avatar.png
A record corresponding to a file, if the delete operation needs to delete the database records that record corresponding file, if the database delete operations and file deletion of "atomicity"?
Reply content:
is not a specific technical problem, just come here to ask you a solution.As follows: If there is a record in th
[System architecture] cache MEMCACHE uses atomic operation add to implement concurrency lock and memcacheadd
Original article address
MemcacheMemcache: add ()Method does not exist before the Cache ServerkeyTokeyStore a variable as a keyvarTo the cache server. We use add to add a key-value correspondence to the server. If it is successfully added, otherwise another concurrent job is being operated. The atomicity of add is used to determine whether hots
thrown, and a problem occurs: in the case of multithreading, when the current thread executes to change the City to "Qingdao ", however, when Zip and Province are not modified yet (Zip is still "710068" and Province is still "Shaanxi "). If other threads access instance a at this time, the inconsistent data will also be read.
Constants and atomicityNow that we know the problem above, how can we improve it? Let's take a look at the author's definition of constants and atomicity:
Atomicity of an
Interlocked, an atomic operation in C #, do you really understand it ?,
Reading directory
Background
Code Description
The darker the analysis
Conclusion
I. background
This title starts with a bit of suspicion from the title party [cover your face]. The original principle of this case is that there is a problem when a Web API site uses the Release mode Run locally, but not in Debug mode. Locate the problem by logging in the following code:
Priva
. The 12th to 21st line simulates the counting process, assuming that about 60% of the people voted in favour and that the vote was random. Line 17th modifies the Candidate.score (which should be thread safe) using updater, and the 18th line uses the Atomicinteger count as the reference datum.If you run this program, it is not difficult to find that the final candidate.score is always equal to Allscore. This shows that Atomicintegerfieldupdater is a good way to ensure candidate.score thread safe
int someint=0;InterlockedIncrement (someint);//self-incrementInterlockedDecrement (someint);//self-reductionThe execution of InterlockedDecrement (someint) is such that {__ prohibits other threads from accessing (someint) This address someint--;move EAX, someint;//Set return value, C + + The return value of the function is placed in eax, and __ opens the other thread to access (someint) this address}Atomic addition and subtraction of multi-threaded me
"); Thread.Sleep (500); } Catch(Interruptedexception ex) {ex.printstacktrace (); } System.out.println (Thread.CurrentThread (). GetName ()+ "woke up."); Account.withdraw (amount); System.out.println (Thread.CurrentThread (). GetName ()+ "completes the withdrawl"); } Else{System.out.println ("Sorry, not enough for" +Thread.CurrentThread (). GetName ()); } }}Ryan is on to withdrawRyan is going to sleepRyan woke up.Ryan completes the withdrawlRyan is on to withdrawRyan is goin
Overview
This is the seventh section of the book "Effective C #" reading notes. Through this article, I would like to tell you about a problem that we may not notice at ordinary times: Create a value type that is constant and atomic.
Starting from the type design
From class to struct
If we are going to design a type that stores the address of the recipient, we call this a type. It should contain such several attributes:
Province Province
City
Z
Various situations ensure the correctness and completeness of the data. Public classTestmultithreadImplementsRunnable {Private Static inti; Private Static volatileInteger VI = 0; Private StaticAtomicinteger ai =NewAtomicinteger (); Private StaticInteger si = 0; Private StaticInteger ia = 1; Private Static intRI; Private StaticAtomicinteger flag =NewAtomicinteger (); Private StaticLock lock =NewReentrantlock ();//If lock does not add the static keyword, then each thread will be locked to a specif
. NET synchronous and asynchronous atomic operations and spin locks (Interlocked, SpinLock) (9), cinterlockedlock
This additional link:. NET synchronization and Asynchronization lock (ReaderWriterLockSlim) (8)
As mentioned above, although locking can effectively solve the competition conditions, it also has a negative impact: performance. Is there a better solution? Yes. Atomic operations, that is, Interlo
Document directory
From class to struct
Data inconsistency
Constants and atomicity
Avoid external access to internal types
Overview
This article is the seventh part of Objective C. Through this article, I mainly want to explain to you a problem that we may not notice at ordinary times: creating constant and atomic value types.From type design to class to struct
If we want to design a type that stores the recipient's address, we call this type ad
The underlying implementation of CAs in Java Atomic classFrom Java to C + + to the assembly, the underlying principles of CAs are explained in depth.Before introducing the principle, start with a demoTake the Atomicboolean class as an example. Let's start with a demo that calls CAs.The main thread in the For statement CAS is busy looping until the CAS operation successfully returns TRUE.The newly opened county new thread will set flag to true after 4
Recently learning some knowledge of high concurrency, when learning to Atomic, run the program, not the same as expectedThe code is as follows Public classLearn13 {atomicinteger count=NewAtomicinteger (0); voidm () { for(inti= 0; i) count.getandincrement (); } Public Static voidMain (string[] args) {FinalLearn12 Learn =NewLearn12 (); Runnable R=NewRunnable () {@Override Public voidrun () {learn.m (); } }; ListNewArray
Type __sync_fetch_and_add (type *ptr, type value);Type __sync_fetch_and_sub (type *ptr, type value);Type __sync_fetch_and_or (type *ptr, type value);Type __sync_fetch_and_and (type *ptr, type value);Type __sync_fetch_and_xor (type *ptr, type value);Type __sync_fetch_and_nand (type *ptr, type value);Type __sync_add_and_fetch (type *ptr, type value);Type __sync_sub_and_fetch (type *ptr, type value);Type __sync_or_and_fetch (type *ptr, type value);Type __sync_and_and_fetch (type *ptr, type value);T
Java 5 Application of the original sub-operation class, Java 5 atomic type
The java. util. concurrent. atomic package provides operations for basic data types, basic data types in arrays, and basic data types in classes. For more information, see API.
The following example briefly introduces the use of the AtomicInteger class:
1 public class AtomicTest { 2 public static void main(String[] args) { 3
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.