static member function and thread-safety

不羁岁月 提交于 2019-12-04 02:29:38

They are local unless you declare them static - each invokation of the function will have its own copy of the variable and you don't need to to protect them.

myint is local for somefunc and you don't need to protect it across threads.

myint in your example is a local variable, every time somefunc is called myint lives. but not more than that.

myint doesn't need to be protected because its a local variable

myint will truly be local. You don't have to worry about protecting it. A separate space will be created on the stack for myint for every single function call in memory.

The myint variable will stay local, there is no need to protect them since each thread will not share the local variables.

The static key-word means that the function will not be passed a hidden "this" argument. Also the function will not have access to the class instance data. The static qualifier of function, has no impact on function's local data.

The static RetType SomeClass::SomeMethod(Type arg) has the same "type" as a free functionRetType SomeFunc(Type arg)

Regards,
Marcin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!