In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article to share with you is about Java memory model instruction rearrangement is what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.
JMM is the memory model specification embodied in the Java language. JMM guarantees atomicity, visibility, and orderliness of shared variable reads and writes in a multi-core CPU multithreaded programming environment.
instruction rearrangement
Before we talk about order, we have to talk about order reordering, because if there were no order rebeats, there would be no order problem.
Instruction rearrangement refers to the reordering of instructions of source code by compilers and processors without affecting the result of code single-thread execution. This reordering execution is an optimization method, the purpose is to make full use of the processor's internal computing units, and improve the overall running efficiency of the program.
There are several types of reordering:
Compiler-optimized reordering.
The compiler can rearrange the execution order of statements without changing the semantics of a single-threaded program.
Instruction level parallel reordering.
Modern processors employ instruction-level parallelism to overlap multiple instructions. If there are no data dependencies, the processor can change the order of execution of the machine instructions corresponding to the statement.
Reordering of memory systems.
Because the processor uses cache and read/write buffers, this makes load and store operations appear likely to be performed out of order.
From the definition of instruction rearrangement, it can be seen that instruction rebeat can only guarantee the correctness of single-thread execution, and in multi-thread environment, instruction rearrangement will bring certain problems (a coin has two sides, instruction rearrangement brings performance improvement and also increases programming complexity). Let's show you an example of how instruction rearrangement affects the execution of a program.
For the above code, if we open a thread to call startSystem, and then open a thread to repeatedly call checkStartes method, we cannot guarantee that the code will execute to the "point of concern", the var variable must have a value of 3. Because the two assignment statements in the startSystem method do not have dependencies, instruction rearrangement may occur when the compiler compiles code.
That is to say, start =true is executed first; after executing this statement, the thread immediately executes the checkStarts method, and the value value is still 1, so the var value at the point of concern is 2 instead of 3 as we thought.
The above is what the Java memory model instruction rearrangement is, Xiaobian believes that some knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.