ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved