Out-of-order writes for Double-checked locking

前端 未结 4 1470
予麋鹿
予麋鹿 2021-02-06 15:44

In the examples mentioned for Out-of-order writes for double-checked locking scenarios (ref: IBM article & Wikipedia Article)

I could not understand the simple reaso

4条回答
  •  不知归路
    2021-02-06 16:26

    The constructor can have completed - but that doesn't mean that all the writes involved within that constructor have been made visible to other threads. The nasty situation is when the reference becomes visible to other threads (so they start using it) before the contents of the object become visible.

    You might find Bill Pugh's article on it helps shed a little light, too.

    Personally I just avoid double-checked locking like the plague, rather than trying to make it all work.

提交回复
热议问题