What is the meaning of the term “thread-safe”?

前端 未结 18 1910
孤独总比滥情好
孤独总比滥情好 2020-11-22 13:51

Does it mean that two threads can\'t change the underlying data simultaneously? Or does it mean that the given code segment will run with predictable results when multiple t

18条回答
  •  遥遥无期
    2020-11-22 14:24

    I like the definition from Brian Goetz's Java Concurrency in Practice for its comprehensiveness

    "A class is thread-safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code."

提交回复
热议问题