I want to run some part of my command line programm in parallel with multiple threads and I am afraid that there might be some static variable left that I must fix (e.g. by making it [ThreadStatic]
). Is there any tool or easy way to find these in my project?
Of course simply searching for "static"
does not help much: I have lots of static methods that work great and finde with any number of threads
The static variables are stored in the data segment of the memory. The data segment is a part of the virtual address space of a program. All the static variables that do not have an explicit initialization or are initialized to zero are stored in the uninitialized data segment( also known as the BSS segment).
We cannot access directly instance variables from a static method. Therefore, to access an instance variable, we must have an instance of the class from which we access the instance variable.
Syntax and Use of the Static Variable in COne can define a static variable both- outside or inside the function. These are local to the block, and their default value is always zero. The static variables stay alive till the program gets executed in the end.
A data segment is a portion of the virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.
Note: dasblinkenlight's answer works only on Visual Studio 2010 and older.
Below is the translation for Visual Studio 2012 and newer:
static(?([^\r\n])\s)+(\b(_\w+|[\w-[0-9_]]\w*)\b)(?([^\r\n])\s)+(\b(_\w+|[\w-[0-9_]]\w*)\b)(?([^\r\n])\s)*[=;]
Translation was made referencing: http://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.110).aspx
Searching your files for static:b+:i:b+:i:b*[=;]
with regexp option in Visual Studio should turn up static variables for you. It will also bring operators ==
, but they should be relatively easy to filter out visually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With