青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

S.l.e!ep.¢%

像打了激速一樣,以四倍的速度運轉,開心的工作
簡單、開放、平等的公司文化;尊重個性、自由與個人價值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

Memory barrier

Posted on 2014-11-13 15:16 S.l.e!ep.¢% 閱讀(483) 評論(0)  編輯 收藏 引用 所屬分類: English

Memory barrier

內存屏障

From Wikipedia, the free encyclopedia
Jump to: navigation, search

A memory barrier, also known as a membar, memory fence or fence instruction,

內存屏障, 也被稱為構件?內存 柵欄或 柵欄指令

is a type of barrierinstruction which causes a central processing unit (CPU) or compiler to enforce an ordering constraint on memory operations issued before and after the barrier instruction.

是柵欄指令的一種類型,讓cpu或編譯器在 柵欄指令前后內存操作的強制一致性

This typically means that operations issued prior to the barrier are guaranteed to be performed before operations issued after the barrier.

Memory barriers are necessary because most modern CPUs employ performance optimizations that can result in out-of-order execution. This reordering of memory operations (loads and stores) normally goes unnoticed within a single thread of execution, but can cause unpredictable behaviour in concurrent programs and device drivers unless carefully controlled. The exact nature of an ordering constraint is hardware dependent and defined by the architecture's memory ordering model. Some architectures provide multiple barriers for enforcing different ordering constraints.

Memory barriers are typically used when implementing low-level machine code that operates on memory shared by multiple devices. Such code includes synchronization primitives and lock-free data structures on multiprocessor systems, and device drivers that communicate with computer hardware.

An illustrative example [ edit ]

When a program runs on a single-CPU machine, the hardware performs the necessary bookkeeping to ensure that the program executes as if all memory operations were performed in the order specified by the programmer (program order), so memory barriers are not necessary. However, when the memory is shared with multiple devices, such as other CPUs in a multiprocessor system, or memory mapped peripherals, out-of-order access may affect program behavior. For example, a second CPU may see memory changes made by the first CPU in a sequence which differs from program order.

The following two-processor program gives an example of how such out-of-order execution can affect program behavior:

Initially, memory locations x and f both hold the value 0. The program running on processor #1 loops while the value of f is zero, then it prints the value of x. The program running on processor #2 stores the value 42 into x and then stores the value 1 into f. Pseudo-code for the two program fragments is shown below. The steps of the program correspond to individual processor instructions.

Processor #1:

												while
												(f ==0);// Memory fence required here
 print x;

Processor #2:

 x =42;// Memory fence required here
 f =1;

One might expect the print statement to always print the number "42"; however, if processor #2's store operations are executed out-of-order, it is possible for f to be updated beforex, and the print statement might therefore print "0". Similarly, processor #1's load operations may be executed out-of-order and it is possible for x to be read beforef is checked, and again the print statement might therefore print an unexpected value. For most programs neither of these situations are acceptable. A memory barrier can be inserted before processor #2's assignment to f to ensure that the new value of x is visible to other processors at or prior to the change in the value of f. Another can be inserted before processor #1's access to x to ensure the value of x is not read prior to seeing the change in the value of f.

For another illustrative example (a non-trivial one that arises in actual practice), see double-checked locking.

Low-level architecture-specific primitives [ edit ]

Memory barriers are low-level primitives and part of an architecture's memory model, which, like instruction sets, vary considerably between architectures, so it is not appropriate to generalize about memory barrier behavior. The conventional wisdom is that using memory barriers correctly requires careful study of the architecture manuals for the hardware being programmed. That said, the following paragraph offers a glimpse of some memory barriers which exist in contemporary products.

Some architectures, including the ubiquitous x86/x64, provide several memory barrier instructions including an instruction sometimes called "full fence". A full fence ensures that all load and store operations prior to the fence will have been committed prior to any loads and stores issued following the fence. Other architectures, such as the Itanium, provide separate "acquire" and "release" memory barriers which address the visibility of read-after-write operations from the point of view of a reader (sink) or writer (source) respectively. Some architectures provide separate memory barriers to control ordering between different combinations of system memory and I/O memory. When more than one memory barrier instruction is available it is important to consider that the cost of different instructions may vary considerably.

Multithreaded programming and memory visibility [ edit ]

Multithreaded programs usually use synchronization primitives provided by a high-level programming environment, such as Java and .NET Framework, or an application programming interface (API) such as POSIX Threads or Windows API. Primitives such as mutexes and semaphores are provided to synchronize access to resources from parallel threads of execution. These primitives are usually implemented with the memory barriers required to provide the expected memory visibility semantics. In such environments explicit use of memory barriers is not generally necessary.

Each API or programming environment in principle has its own high-level memory model that defines its memory visibility semantics. Although programmers do not usually need to use memory barriers in such high level environments, it is important to understand their memory visibility semantics, to the extent possible. Such understanding is not necessarily easy to achieve because memory visibility semantics are not always consistently specified or documented.

Just as programming language semantics are defined at a different level of abstraction than machine languageopcodes, a programming environment's memory model is defined at a different level of abstraction than that of a hardware memory model. It is important to understand this distinction and realize that there is not always a simple mapping between low-level hardware memory barrier semantics and the high-level memory visibility semantics of a particular programming environment. As a result, a particular platform's implementation of (say) POSIX Threads may employ stronger barriers than required by the specification. Programs which take advantage of memory visibility as implemented rather than as specified may not be portable.

Out-of-order execution versus compiler reordering optimizations [ edit ]

Memory barrier instructions address reordering effects only at the hardware level. Compilers may also reorder instructions as part of the program optimization process. Although the effects on parallel program behavior can be similar in both cases, in general it is necessary to take separate measures to inhibit compiler reordering optimizations for data that may be shared by multiple threads of execution. Note that such measures are usually necessary only for data which is not protected by synchronization primitives such as those discussed in the prior section.

In C and C++, the volatile keyword was intended to allow C and C++ programs to directly access memory-mapped I/O. Memory-mapped I/O generally requires that the reads and writes specified in source code happen in the exact order specified with no omissions. Omissions or reorderings of reads and writes by the compiler would break the communication between the program and the device accessed by memory-mapped I/O. A C or C++ compiler may not reorder reads from and writes to volatile memory locations, nor may it omit a read from or write to a volatile memory location. The keyword volatiledoes not guarantee a memory barrier to enforce cache-consistency. Therefore the use of "volatile" alone is not sufficient to use a variable for inter-thread communication on all systems and processors.[1]

The C and C++ standards prior to C11 and C++11 do not address multiple threads (or multiple processors),[2] and as such, the usefulness of volatile depends on the compiler and hardware. Although volatile guarantees that the volatile reads and volatile writes will happen in the exact order specified in the source code, the compiler may generate code (or the CPU may re-order execution) such that a volatile read or write is reordered with regard to non-volatile reads or writes, thus limiting its usefulness as an inter-thread flag or mutex. Preventing such is compiler specific, but some compilers, like gcc, will not reorder operations around in-line assembly code with volatile and "memory" tags, like in: asm volatile (""?:?:?: "memory"); (See more examples in compiler memory barrier). Moreover, it is not guaranteed that volatile reads and writes will be seen in the same order by other processors or cores due to caching, cache coherence protocol and relaxed memory ordering, meaning volatile variables alone may not even work as inter-thread flags or mutexes.

Some languages and compilers may provide sufficient facilities to implement functions which address both the compiler reordering and machine reordering issues. In Java version 1.5 (also known as version 5), the volatile keyword is now guaranteed to prevent certain hardware and compiler re-orderings, as part of the new Java Memory Model. C++11 standardizes special atomic types and operations with semantics similar to those of volatile in the Java Memory Model.

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品久久久久秋霞鲁丝 | 久久久女女女女999久久| 亚洲国产乱码最新视频| 亚洲无玛一区| 一区二区三区免费在线观看| 久久久久www| 久久久噜噜噜久久中文字免| 国产精品盗摄久久久| 最新国产の精品合集bt伙计| 狠狠综合久久| 欧美中文字幕在线观看| 欧美伊久线香蕉线新在线| 欧美视频中文一区二区三区在线观看| 亚洲电影第三页| 亚洲大片在线| 久久影视三级福利片| 另类国产ts人妖高潮视频| 国产亚洲精品bt天堂精选| 午夜精品视频一区| 久久av老司机精品网站导航| 国产乱码精品一区二区三| 亚洲自拍偷拍一区| 小辣椒精品导航| 国产精品色在线| 欧美亚洲一区三区| 久久频这里精品99香蕉| 一区二区三区在线免费视频| 久久久久www| 欧美成人午夜剧场免费观看| 亚洲激情精品| 欧美国产日韩亚洲一区| 99精品欧美一区| 午夜久久tv| 国模精品娜娜一二三区| 久久夜色精品国产亚洲aⅴ| 欧美激情精品久久久久久久变态| 一区在线播放| 欧美精品观看| 亚洲网址在线| 久久一二三国产| 亚洲美女中文字幕| 国产精品久久久久久超碰| 亚洲欧美日韩国产中文| 久久深夜福利免费观看| 亚洲青涩在线| 欧美日韩中文字幕综合视频| 中文欧美日韩| 老司机凹凸av亚洲导航| 亚洲精品国产欧美| 国产精品嫩草99av在线| 久久国产88| 亚洲国产美国国产综合一区二区| 亚洲图片激情小说| 国产一区二区久久久| 欧美大香线蕉线伊人久久国产精品| 99视频在线观看一区三区| 久久精品视频亚洲| 亚洲精品一二区| 国产欧美一区二区三区久久| 久久夜色精品亚洲噜噜国产mv| 亚洲美女av电影| 久久久久久亚洲综合影院红桃| 亚洲人成77777在线观看网| 国产精品v片在线观看不卡| 久久精品麻豆| 在线亚洲伦理| 亚洲国产高清视频| 久久国产精品久久国产精品| 亚洲精品在线视频| 韩国三级电影一区二区| 欧美日韩1区| 老司机亚洲精品| 亚洲欧美伊人| 一本色道久久| 亚洲激情网址| 欧美不卡在线视频| 欧美在线视频免费观看| 在线一区二区三区四区| 久久美女性网| 亚洲一区三区视频在线观看| 亚洲国产日韩欧美| 国产亚洲精品福利| 国产精品日日做人人爱 | 欧美一区日本一区韩国一区| 欧美激情第三页| 久久久91精品| 亚洲欧美中文日韩在线| 一个色综合av| 亚洲激情视频在线播放| 激情校园亚洲| 国产一区日韩二区欧美三区| 国产精品久久久久久久电影| 欧美久久电影| 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲一区二区毛片| 亚洲精品日韩精品| 亚洲国产精品一区在线观看不卡 | 亚洲欧美日韩精品久久亚洲区| 亚洲欧洲偷拍精品| 在线精品国产欧美| 黑人巨大精品欧美一区二区小视频| 国产精品三级久久久久久电影| 欧美午夜大胆人体| 欧美日韩免费观看中文| 欧美区亚洲区| 欧美日韩亚洲一区二| 欧美日本不卡视频| 欧美日韩1区| 一本色道久久综合狠狠躁篇怎么玩| 美日韩精品视频免费看| 欧美一级精品大片| 亚洲综合国产激情另类一区| 在线一区二区三区四区| 一区二区三区黄色| 亚洲一区bb| 亚洲欧美日韩一区在线观看| 亚洲欧美日韩在线观看a三区| 亚洲男女自偷自拍图片另类| 亚洲欧美色婷婷| 久久精品噜噜噜成人av农村| 久久久久久欧美| 免费成人av在线看| 欧美人与禽猛交乱配| 欧美视频你懂的| 国产美女搞久久| 精久久久久久| 亚洲精品日本| 亚洲一区二区不卡免费| 欧美一级在线亚洲天堂| 久久精品国产69国产精品亚洲| 久久久免费av| 亚洲国产裸拍裸体视频在线观看乱了中文 | 性久久久久久| 久久先锋资源| 欧美日韩精品一本二本三本| 国产精品久久久久久久久婷婷| 国产日韩欧美二区| 精品51国产黑色丝袜高跟鞋| 亚洲国产精品一区制服丝袜| 一本色道久久综合亚洲精品高清 | 国产精品成人一区二区三区夜夜夜 | 欧美激情一区二区三区在线| 欧美午夜免费影院| 激情综合在线| 亚洲五月六月| 欧美69视频| 亚洲图片你懂的| 老司机午夜精品视频| 国产精品v亚洲精品v日韩精品| 激情婷婷久久| 亚洲调教视频在线观看| 久久一区二区三区四区| 日韩午夜在线电影| 久久女同互慰一区二区三区| 国产精品第十页| 亚洲激情视频在线观看| 久久国产婷婷国产香蕉| 亚洲人成网站777色婷婷| 欧美一区二区私人影院日本 | 亚洲国产视频一区二区| 欧美亚洲自偷自偷| 亚洲激情第一区| 久久久av水蜜桃| 国产精品极品美女粉嫩高清在线| 亚洲电影欧美电影有声小说| 亚洲欧美在线另类| 亚洲精品一区在线观看| 久久亚洲一区| 激情丁香综合| 欧美在线视频一区| 一区二区高清在线观看| 欧美电影资源| 亚洲国产影院| 毛片一区二区三区| 性感少妇一区| 国产精品人人做人人爽| 亚洲午夜国产成人av电影男同| 亚洲国产欧美日韩| 久久久天天操| 一区精品在线播放| 久久综合激情| 久久久www| 激情久久婷婷| 免费成人高清视频| 久久一二三区| 亚洲国产精品精华液网站| 欧美成人tv| 玖玖玖国产精品| 亚洲激情成人网| 亚洲激情小视频| 欧美日本高清视频| 亚洲视频日本| 亚洲一区二区三区视频播放| 国产精品xxxav免费视频| 亚洲天堂视频在线观看| 亚洲视频欧美视频| 国产精品视频九色porn| 久久激情久久| 久久久久成人精品免费播放动漫| 在线不卡视频|