Boost logo

Boost Users :

Subject: Re: [Boost-users] [system] local static and threading in C++03
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2012-12-27 14:42:50


Felipe Magno de Almeida wrote
> On Thu, Dec 27, 2012 at 9:30 AM, Vicente Botet <

> vicente.botet@

> > wrote:
>> Felipe Magno de Almeida wrote
>>> Hello Vicente,
>>>
>>> On Tue, Dec 25, 2012 at 6:28 PM, Vicente Botet <
>>
>>> vicente.botet@
>>
>>> > wrote:
>>>> Felipe Magno de Almeida wrote
>>>>> Hello,
>>>
>>> [snip - source code]
>>>
>>>>> But couldn't this make double construction/double free in C++03
>>>>> systems
>>>>> if system_category is ran concurrently?
>>>>
>>>> Yes sure, this is always possible zith c++0·.
>>>
>>> Not always possible. It is only possible for non-PODs. AFAIK.
>>>
>>>> Do you see a problem with this implementation?
>>>
>>> Since it has a race-condition, I would say I see a problem, yes.
>>> More so since it is not documented.
>>
>> Form a theoretical point of view yes. But in practice, which observable
>> problems could induce the double construction?

Could you answer this question?

>> I would expect only one destruction, don`t you?
>
> No, I wouldn't. If it is constructed twice, I would expect atexit to be
> called
> twice as well. So double destruction.

I don`t know. Anyway, which observable problems could induce this double
destruction?

>>> AFAIK, the normal solution
>>> for this is to use call_once.
>>>
>>> system_category const& create_system_category()
>>> {
>>> system_category const category;
>>> return category;
>>> }
>>> void init_system_category() { create_system_category(); }
>>> once_flag init_flag = BOOST_ONCE_INIT;
>>>
>>> system_category const& get_system_category()
>>> {
>>> boost::call_once(init_flag, &init_system_category);
>>> return create_system_category();
>>> }
>>
>> This approach would make both libraries interdependent.
>
> I don't understand what you mean.

Boost.System will depend on Boost.Thread and Boost.Thread already depends on
Boost.System.

Best,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/system-local-static-and-threading-in-C-03-tp4640524p4640627.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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