How to define threadsafe?

后端 未结 8 1969
夕颜
夕颜 2020-12-31 11:48

Threadsafe is a term that is thrown around documentation, however there is seldom an explanation of what it means, especially in a language that is understandab

相关标签:
8条回答
  • 2020-12-31 12:21

    Eric Lippert says:

    When I'm asked "is this code thread safe?" I always have to push back and ask "what are the exact threading scenarios you are concerned about?" and "exactly what is correct behaviour of the object in every one of those scenarios?".

    It is unhelpful to say that code is "thread safe" without somehow communicating what undesirable behaviors the utilized thread safety mechanisms do and do not prevent.

    0 讨论(0)
  • 2020-12-31 12:22

    i maybe wrong but one of the criteria for being thread safe is to use local variables only. Using global variables can have undefined result if the same function is called from different threads.

    0 讨论(0)
提交回复
热议问题