Hello Ronald, thanks for the reply.
Unfortunately, I don't have any experience with global functions in C++ so I
don't really comprehend what you are saying.
My concern is that I don't know if variables inside a static method are also
static by default? Because I am writing a DLL which contains functions that
could be called at any time... What happens if two programs, running at the
same time, call the same function from the DLL? Will the data be corrupted?
Or can the same static function be called twice at the same time without
interference?
The reason I am questioning this is that we have several dual CPU machines,
and some of the programs I'm writing take several minutes to complete.
These programs will call Static Methods in the DLL I am currently writing.
These Static Methods are meant as individual functions and should not
"share" any variables. So I don't know if I can actually use Static Methods
in this case?
Does this make sense?
Thanks,
/\/\ark
> My concern is that I don't know if variables inside a static method are
> also static by default? Because I am writing a DLL which contains
> functions that could be called at any time... What happens if two
> programs, running at the same time, call the same function from the DLL?
> Will the data be corrupted? Or can the same static function be called
> twice at the same time without interference?
Normally, variables introduced inside static functions are local to the
function invocation (they are on the specific thread's execution stack).
Thus they do not need to be protected by synchronization devices in
multi-threaded programs.
If a local variable is introduced with the 'static' keyword, then it is
shared between all invocations of that function. It is subject to race
conditions in a multi-threaded program.
It is very unlikely that you would want to introduce a static variable
inside a static function unless you really understand what you are doing and
have experience with multithreaded programming.
> The reason I am questioning this is that we have several dual CPU
> machines, and some of the programs I'm writing take several minutes to
> complete. These programs will call Static Methods in the DLL I am
> currently writing. These Static Methods are meant as individual functions
> and should not "share" any variables. So I don't know if I can actually
> use Static Methods in this case?
It sounds like you're fine.

Signature
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Mark Prenter - 14 Jul 2004 00:25 GMT
Thanks very much guys!!!
I feel much better now. :-)
/\/\ark
> > My concern is that I don't know if variables inside a static method are
> > also static by default? Because I am writing a DLL which contains
[quoted text clipped - 24 lines]
>
> It sounds like you're fine.