Best programming approach/methodology to assure thread safety

前端 未结 15 1655
一整个雨季
一整个雨季 2021-01-31 06:28

When I was learning Java coming from a background of some 20 years of procedural programming with basic, Pascal, COBOL and C, I thought at the time that the hardest thing about

相关标签:
15条回答
  • 2021-01-31 07:17

    I suggest the actor model.

    0 讨论(0)
  • 2021-01-31 07:25
    1. Avoid sharing data between threads where possible (copy everything).
    2. Never have locks on method calls to external objects, where possible.
    3. Keep locks for the shortest amount of time possible.
    0 讨论(0)
  • 2021-01-31 07:25

    Writing all the code in a multi-threaded application very... carefully! I don't know any better answer than that. (This involves stuff like jonnii mentioned).

    I've heard people argue (and agree with them) that the traditional threading model really won't work going into the future, so we're going to have to develop a different set of paradigms / languages to really use these newfangled multi-cores effectively. Languages like Haskell, whose programs are easily parallelizable since any function that has side effects must be explicitly marked that way, and Erlang, which I unfortunately don't know that much about.

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