Static Function Concurrency ASP.NET

后端 未结 7 1393
遇见更好的自我
遇见更好的自我 2021-02-09 19:14

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 19:50

    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.

提交回复
热议问题