并发基本名词解释

来源:互联网 发布:js根据id隐藏div 编辑:程序博客网 时间:2024/06/05 21:05

Intra-thread semantics(线程内语义):

            The memory model determines what values can be read at every point in the program. The actions of each thread in isolation must behave as governed by the semantics of that thread, with the exception that the values seen by each read are determined by the memory model. When we refer to this, we say that the program obeys intra-thread semantics.Intra-thread semantics are the semantics for singlethreaded programs, and allow the complete prediction of the behavior of a thread based on the values seen by read actions within the thread. To determine if the actions of thread t in an execution are legal, we simply evaluate the implementation of thread t as it would be performed in a single-threaded context, as defined in the rest of this specification.(Java Language Specification)
        

Inter-thread action(线程间语义):

          An inter-thread action is an action performed by one thread that can be detected or
directly influenced by another thread. There are several kinds of inter-thread action
that a program may perform:
    • Read (normal, or non-volatile). Reading a variable.
    • Write (normal, or non-volatile). Writing a variable.
    • Synchronization actions, which are:
        – Volatile read. A volatile read of a variable.
        – Volatile write. A volatile write of a variable.
        – Lock. Locking a monitor
        – Unlock. Unlocking a monitor.
        – The (synthetic) first and last action of a thread.
        – Actions that start a thread or detect that a thread has terminated (§17.4.4).
     • External Actions. An external action is an action that may be observable outside
of an execution, and has a result based on an environment external to the
execution.
     • Thread divergence actions (§17.4.9). A thread divergence action is only
performed by a thread that is in an infinite loop in which no memory,
synchronization, or external actions are performed. If a thread performs a thread
divergence action, it will be followed by an infinite number of thread divergence
actions.


Program Order(程序顺序):

               Among all the inter-thread actions performed by each thread t, the program order of t is a total order that reflects the order in which these actions would be performed according to the intra-thread semantics of t.(Java Language Specification)
               For execution of a single thread, the rules are simple. The Java Language Specification requires a Java Virtual Machine to observe within-thread as-if-serial semantics. The runtime (which, in this case, usually refers to the dynamic compiler, the processor and the memory subsystem) is free to introduce any useful execution optimizations as long as the result of the thread in isolation is guaranteed to be exactly the same as it would have been had all the statements been executed in the order the statements occurred in the program (also called program order).
             Mathematically, there is a partial order called the happens-before order over all actions performed by the program. The happens-before order subsumes the program order; if one action occurs before another in the program order, it will occur before the other in the happens-before order. In addition, releases and subsequent acquires of locks form edges in the happens-before graph. A read is allowed to return the value of a write if that write is the last write to that variable before the read along some path in the happens-before order, or if the write is not ordered with respect to that read in the happens-before order.(http://en.wikipedia.org/wiki/Java_Memory_Model)


Sequentially Consistent:

               A set of actions is sequentially consistent if all actions occur in a total order (the
execution order) that is consistent with program order, and furthermore, each read
r of a variable v sees the value written by the write w to v such that:
        • w comes before r in the execution order, and
        • there is no other write w' such that w comes before w' and w' comes before r in the execution order.
Sequential consistency is a very strong guarantee that is made about visibility and ordering in an execution of a program.Within a sequentially consistent execution, there is a total order over all individual actions (such as reads and writes) which is consistent with the order of the program, and each individual action is atomic and is immediately visible to every thread. If a program has no data races, then all executions of the program will appear to be sequentially consistent. Sequential consistency and/or freedom from data races still allows errors arising from groups of operations that need to be perceived atomically and are not.
           
0 0
原创粉丝点击