Double checked locking Article

后端 未结 10 673
别那么骄傲
别那么骄傲 2020-12-09 20:06

I was reading this article about \"Double-Checked locking\" and out of the main topic of the article I was wondering why at some point of the article the author uses the nex

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 20:45

    The point of locking twice was to attempt to prevent out-of-order writes. The memory model specifies where reorderings can occur, partly in terms of locks. The lock ensures that no writes (including any within the singleton constructor) appear to happen after the "instance = inst;" line.

    However, to go deeper into the subject I'd recommend Bill Pugh's article. And then never attempt it :)

提交回复
热议问题