On Tue, Feb 21, 2017 at 12:28 PM, Daniel Krügler
<daniel.krueg...@gmail.com> wrote:
> Thread-safe initialization of static local function variables is part
> of C++11, via
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm
>
> but
>
> (a) at least some implementations still do not support them, or
> (b) provide means (outside of the spec) that allow to disable this
> functionality (gcc: --fno-threadsafe-statics, Visual Studio 2015:
> /Zc:threadSafeInit-).
>
> The compilers I am aware of both don't provide a vendor specific
> feature macro to detect this situation.
>
> I would therefore strongly vote for a feature macro that describes the
> presence of that functionality, because user code can usually defend
> against this missing feature by means of std::call_once. Here is
> therefore a minimalistic example code hopefully suitable for a future
> revision of p0096 (The example also shows my current feature macro
> name suggestion as "__cpp_threadsafe_static_init"):
>
> Thingy& get_thing()
> {
> #ifndef __cpp_threadsafe_static_init
>     [...]
>     static std::once_flag flag;
>     std::call_once(flag, init::get);
>     return init::get();
> #else
>     static Thingy result;
>     return result;
> #endif
> }

Sounds good to me.

Jason
_______________________________________________
Features mailing list
Features@isocpp.open-std.org
http://www.open-std.org/mailman/listinfo/features

Reply via email to