Boost logo

Boost :

Subject: Re: [boost] [thread] thread-safe static local
From: Othman, Ossama (ossama.othman_at_[hidden])
Date: 2009-03-03 12:43:14


Hi,

>As you may know, gcc creates local statics that are thread safe by
>default. So I have a macro something like this:
>
>#if __GCC__
>#define THREAD_SAFE_STATIC(TYPE,NAME) static TYPE NAME;
>#else
>#define THREAD_SAFE_STATIC(TYPE,NAME) #error FIXME
>#endif
>
>If your code can be used in the #else case, that would be great. I
>think it's important to use the gcc feature when available as the
>alternative will probably involve an unnecessary extra layer of locking.

Is there a way to reliably determine if the gcc's thread-safe local statics are enabled? If not, multithreaded library code that relies on that feature, for example, should hide static locals inside an out-of-line function/method in the odd event users of the library disable gcc's thread safe local statics for their own code through the '-fno-threadsafe-statics' command line option.

HTH,
-Ossama


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk