|
|
 |
boost
Re: [boost] Re: Race condition in boost::spirit?
by Peter Dimov other posts by this author
Jan 18 2005 4:13AM messages near this date
[boost] [string_algo, regex] Fix for reg_expression errors?
|
[boost] Re: Race condition in boost::spirit?
SOURCE Stefan Slapeta wrote:
> Roland Schwarz wrote:
>
> [...]
>
> > The broader question is:
> > Can local static objects ever be made thread safe? Or should they be
> > avoided at all in MT aware
> > code?
> >
>
> 1) No
> 2) Yes!!
Local static objects can be made safe by the compiler. The new cxx64 API
requires it.
They can also be made safe by using one of the following two approaches
(pseudocode):
1.
mutex m = MUTEX_INITIALIZER;
void f()
{
mutex_lock(&m);
static X x;
mutex_unlock(&m);
// use x
}
2.
X & instance()
{
static X x;
return x;
}
void f()
{
call_once( instance );
X /*const*/ & x = instance();
// use x
}
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Peter Dimov
Stefan Slapeta
|
|
|
 |
|