Static Function Concurrency ASP.NET

后端 未结 7 1818
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 18:59

If you have two threads invoking a static function at the same moment in time, is there a concurrency risk? And if that function uses a static member of the class, is there even

相关标签:
7条回答
  • 2021-02-09 20:01

    In your two examples, there is no thread safety issues because each call to the function will have it's own copy of the local variables on the stack, and in your first example with 'a' being a static variable, you never change 'a', so there is no problem.

    If you change the value in 'a' in your first example you will have a potential concurrency problem.

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