Java Memory Model: reordering and concurrent locks

后端 未结 4 1124
猫巷女王i
猫巷女王i 2021-02-15 10:22

The java meomry model mandates that synchronize blocks that synchronize on the same monitor enforce a before-after-realtion on the variables modified within those b

4条回答
  •  执笔经年
    2021-02-15 11:24

    From the API-doc:

    All Lock implementations must enforce the same memory synchronization semantics as provided by the built-in monitor lock, as described in The Java Language Specification, Third Edition (17.4 Memory Model):

    * A successful lock operation has the same memory synchronization effects as a successful Lock action.
    * A successful unlock operation has the same memory synchronization effects as a successful Unlock action.
    

    Unsuccessful locking and unlocking operations, and reentrant locking/unlocking operations, do not require any memory synchronization effects.

提交回复
热议问题