|
Boost Users : |
Subject: Re: [Boost-users] [Lambda, Function, etc] Is static dangerous?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-05-23 09:40:06
AMDG
On 05/23/2011 05:52 AM, Robert Jones wrote:
> Hi All
>
> Is it dangerous to write static Boost.Functions or Boost.Lamda placeholders
> in a multi-theaded
> context? I think that might be a really stoopid quesion - I'm just checking!
>
In C++03, local static anything is dangerous,
because the initialization is not guaranteed
to be thread safe. It's safe in C++0x and
both Boost.Function and Boost.Lambda are
safe with parallel reads.
> eg,
>
> #include <boost/function.hpp>
> #include <boost/lambda/bind.hpp>
>
>
> void f( )
> {
> namespace ll = boost::lambda;
> using boost::function;
>
> typedef std::pair<int, int> int_pair;
>
> static ll::placeholder1_type x;
> static function<int(const int_pair &)> second = ll::bind( &
> int_pair::second, x );
> }
>
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net