Should thread-safe class have a memory barrier at the end of its constructor?

前端 未结 4 1895
终归单人心
终归单人心 2020-12-03 17:08

When implementing a class intended to be thread-safe, should I include a memory barrier at the end of its constructor, in order to ensure that any internal structures have c

4条回答
  •  隐瞒了意图╮
    2020-12-03 18:06

    Unrelated, but still interesting that in Java for all final fields that are written inside the constructor there would two fences written after the constructor exists: StoreStore and LoadStore - that would make publishing the reference thread-safe.

提交回复
热议问题