zoukankan      html  css  js  c++  java
  • Sequentially-consistent ordering

    先引入cppreference中的描述:

    Atomic operations tagged memory_order_seq_cst not only order memory the same way as release/acquire ordering (everything that happened-before a store in one thread becomes a visible side effect in the thread that did a load), but also establish a single total modification order of all atomic operations that are so tagged.

    Formally,

    Each memory_order_seq_cst operation B that loads from atomic variable M, observes one of the following:

    • the result of the last operation A that modified M, which appears before B in the single total order
    • OR, if there was such an A, B may observe the result of some modification on M that is not memory_order_seq_cst and does not happen-before A
    • OR, if there wasn't such an A, B may observe the result of some unrelated modification of M that is not memory_order_seq_cst

    然后,让我们查看以下sequentially consistent的模型[1]

    One might expect multiprocessors to have sequentially consistent (SC) shared memory, in which, as articulated by Lamport [Lam79]:
      “the result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program”.
    An SC machine can be modelled as in the diagram below:

    Here there are a number of hardware threads, each executing code as specified by the program, which access a single shared memory (by writing and reading the values it holds at each address). Such a machine has two key properties:
    1. There is no local reordering: each hardware thread executes instructions in the order specified by the program, completing each instruction (including any reads or writes to the shared memory) before starting the next.
    2. Each write becomes visible to all threads (including the thread doing the write) at the same time 

    sequentially consistent模型简单说明:

    (1)按照代码顺序从前到后执行,执行完前一条指令,然后执行下一条指令,不存在指令重排一类的情况。

    (2)所有线程的所有写构成一个序列,如果在两个序列之间(运行时)存在读的话,那么这条读指令,读取的一定是前一条写的结果。

    关于atomic说明:

    如果所有的atomic对象的所有读写操作使用的都是std::memory_order_seq_cst,那么这些所有的atomic对象的操作满足上述的sequentially consistent模型。

  • 相关阅读:
    ByteArrayOutputStream 与InputStream 互相转换
    Java生成和操作Excel文件
    导出excel通用模板(程序定义模板导出)
    使用Swagger2自动生成API接口文档
    The file cannot be validated as theho st "struts.apache.org" is currently unreachable.
    Ubuntu关闭显示器技巧
    Rational License Key Error 的解决办法
    Myeclipse For Blue/Spring/Professional 9.1 破解方法及注册机 JAVA开发相关软件
    没有找到suite objects.dll 因此这个应用程序未能启动
    myEclipse下如何配置Tomcat
  • 原文地址:https://www.cnblogs.com/albizzia/p/8596483.html
Copyright © 2011-2022 走看看