If a variable foo is not declared as volatile, then in the case of a compiler optimization, if you use Foo for the second time, the code generated by the compiler may use the value already stored in the register instead of "reload" the variable from
Volatile Introduction
Volatile is similar to the well-known const and is also a type modifier. Volatile indicates to the compiler that the objects it modifies should not be optimized. Volatile is used for multithreaded programming. In a single
Dark Horse Programmer:Java Training, Android training, iOS training,. NET TrainingJava threading-memory models and volatile explanationsOne, single core memory model1. When the program runs, the temporary data is stored in the cache2. Copy the data
Introduction to VolatileVolatile is similar to what is known as a const is also a type modifier. Volatile is an indication to the compiler that the object it is modifying should not perform optimizations. The role of volatile is to be used for
Introduction
The article describes the internals of volatile fields. I 've seen a lot of discussions in the Web regarding volatile fields. I 've saved med my own small research in this area, and here are some thoughts on this. Volatile fields and
Original net excerpt: Http://www.cnblogs.com/yc_sunniwell/archive/2010/06/24/1764231.htmlThe volatile reminder compiler can change the variables that are defined later, so the compiled program reads the data directly from the variable address each
In some simple examples, for example, to assign a value to a field or increment the field, we need to synchronize the thread,Although the lock can meet our needs, a competitive lock will certainly lead to blocking, and then endure the thread context
Multi-thread lock system (II)-volatile, Interlocked, ReaderWriterLockSlim, interlocked
Introduction
The previous chapter mainly describes the direct use of exclusive locks. However, it is too wasteful to use all the locks in practice, or the
1.volatile
Volatile is primarily used to synchronize variables in multiple threads.Under normal circumstances, to improve performance, each thread saves a variable in its main memory as a copy of the variable in its own memory at run time, but this
IntroducedThe above chapter mainly says the direct use of exclusive locks. But all of the actual use of locks and too wasted, or the exclusive lock granularity is too large. This time we're talking about escalation locks and atomic
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.