static variable thread safe? | | |
Hi,
If i am using static variable in a function, in say a dll. If that dll
is being used by a multi-threaded program, will the static variable be
safe to use? I mean, will it have the problems associated with using
global variables in this case, i.e. same variable being modified by
multiple threads, and hence creating issues...?
Thanks,
Kumar | | | | re: static variable thread safe?
"Kumar" <kumar_gaurava@yahoo.co.uk> wrote in message
news:80965d4.0401100252.36997e2b@posting.google.co m...[color=blue]
> If i am using static variable in a function, in say a dll. If that dll
> is being used by a multi-threaded program, will the static variable be
> safe to use? I mean, will it have the problems associated with using
> global variables in this case, i.e. same variable being modified by
> multiple threads, and hence creating issues...?[/color]
Yes.
(The fact that threads, DLLs and similar stuff is off-topical on this
group is irrelevant ;-))
Peter | | | | re: static variable thread safe?
I wrote:[color=blue]
> "Kumar" <kumar_gaurava@yahoo.co.uk> wrote:[color=green]
> > If i am using static variable in a function, in say a dll. If that dll
> > is being used by a multi-threaded program, will the static variable be
> > safe to use? I mean, will it have the problems associated with using
> > global variables in this case, i.e. same variable being modified by
> > multiple threads, and hence creating issues...?[/color]
>
> Yes.[/color]
On the second thought, I may not have been as clear as I could have been.
The answer is "no" to your first question and "yes" to the other(s).
Peter | | | | re: static variable thread safe?
Peter Pichler wrote:[color=blue]
>
> "Kumar" <kumar_gaurava@yahoo.co.uk> wrote in message
> news:80965d4.0401100252.36997e2b@posting.google.co m...[color=green]
> > If i am using static variable in a function, in say a dll.
> > If that dll
> > is being used by a multi-threaded program,
> > will the static variable be
> > safe to use? I mean, will it have the problems associated with using
> > global variables in this case, i.e. same variable being modified by
> > multiple threads, and hence creating issues...?[/color]
>
> Yes.
>
> (The fact that threads, DLLs and similar stuff is off-topical on this
> group is irrelevant ;-))[/color]
Unless the right answer is really "No".
--
pete | | | | re: static variable thread safe?
"pete" <pfiland@mindspring.com> wrote in message
news:4000001D.7A0@mindspring.com...[color=blue]
> Peter Pichler wrote:[color=green]
> >
> > "Kumar" <kumar_gaurava@yahoo.co.uk> wrote in message
> > news:80965d4.0401100252.36997e2b@posting.google.co m...[color=darkred]
> > > If i am using static variable in a function, in say a dll.
> > > If that dll
> > > is being used by a multi-threaded program,
> > > will the static variable be
> > > safe to use? I mean, will it have the problems associated with using
> > > global variables in this case, i.e. same variable being modified by
> > > multiple threads, and hence creating issues...?[/color]
> >
> > Yes.
> >
> > (The fact that threads, DLLs and similar stuff is off-topical on this
> > group is irrelevant ;-))[/color]
>
> Unless the right answer is really "No".[/color]
It depends on the question ;-) | | | | re: static variable thread safe?
Peter Pichler wrote:[color=blue]
>
> "pete" <pfiland@mindspring.com> wrote in message
> news:4000001D.7A0@mindspring.com...[color=green]
> > Peter Pichler wrote:[color=darkred]
> > >
> > > "Kumar" <kumar_gaurava@yahoo.co.uk> wrote in message
> > > news:80965d4.0401100252.36997e2b@posting.google.co m...
> > > > If i am using static variable in a function, in say a dll.
> > > > If that dll
> > > > is being used by a multi-threaded program,
> > > > will the static variable be
> > > > safe to use? I mean, will it have the problems associated with using
> > > > global variables in this case, i.e. same variable being modified by
> > > > multiple threads, and hence creating issues...?
> > >
> > > Yes.
> > >
> > > (The fact that threads,
> > > DLLs and similar stuff is off-topical on this
> > > group is irrelevant ;-))[/color]
> >
> > Unless the right answer is really "No".[/color]
>
> It depends on the question ;-)[/color]
Anyway, you can convert a function from one that uses a
local static variable, to one that doesn't,
simply by replacing the local static variable
with a parameter which points to an
{automatic variable in the calling function}.
--
pete | | | | re: static variable thread safe?
Kumar wrote:[color=blue]
>
> If i am using static variable in a function, in say a dll. If that
> dll is being used by a multi-threaded program, will the static
> variable be safe to use? I mean, will it have the problems
> associated with using global variables in this case, i.e. same
> variable being modified by multiple threads, and hence creating
> issues...?[/color]
In a word, yes. A static variable is always a 'global', but with
restricted visibility.
--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address! |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|