Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-21 07:51:28


"Gennadiy Rozental" <gennadiy.rozental_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:u1x6xgong.fsf_at_boost-consulting.com...
>>
>> I just tried to compile something with the test library and two
>> translation units. Boom! It was this definition, which appears in
>> boost/test/impl/execution_monitor.ipp.
>
> I wonder which Boost.Test componenent were you using?

Well, minimal test, and I now know it applies only to single TUs, but
the bug would apply to multiple TUs.

>> signal_handler* signal_handler::s_active_handler = NULL; //!! need to be
>> placed in thread
>> specific storage
>
> I would prefer to fix this post release.

I think this is a serious enought bug that it should be addressed
pre-release, FWIW.

>> have this problem. The answer is to initialize a *reference* in the
>> unnamed namespace to a single, common object:
>>
>> namespace whatever
>> {
>> class foo {};
>>
>> template <class T, int = 0>
>> struct unique_instance
>> {
>> T& get()
>> {
>> static T x;
>> return x;
>> };
>> };
>>
>> namespace
>> {
>> foo& bar = unique_instance<foo>::get();
>> }
>> }
>
> This is an idiom I am using in Boost.Test's trivial_singleton.hpp.
>
> Here is a solution for the issue above:
>
> =====================================
> struct active_signal_handler_t : public singleton<active_signal_handler_t> {
> signal_handler* _;
> private:
> BOOST_TEST_SINGLETON_CONS( active_signal_handler_t );
> };
>
> BOOST_TEST_SINGLETON_INST( active_signal_handler )
> =====================================
>
> active_signal_handler._ is s_active_handler above.

That's fine as long as you don't mind using member access syntax.
When you need a non-member, you need something more like my solution.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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