Boost logo

Boost Users :

Subject: Re: [Boost-users] thread-safe initialization for singleton
From: Philipp Kraus (philipp.kraus_at_[hidden])
Date: 2010-08-22 02:59:25


On 2010-08-22 00:12:39 +0200, OvermindDL1 said:

> On Sat, Aug 21, 2010 at 12:59 PM, Kraus Philipp
> <philipp.kraus_at_[hidden]> wrote:
>>
>> Am 21.08.2010 um 17:59 schrieb Mika Heiskanen:
>>
>>> On Sat, 2010-08-21 at 15:58 +0300, Kraus Philipp wrote:
>>>>
>>>> I have written a class with static methods and properties. Now the
>>>> class must be used in a multithreaded environment, so I get some race
>>>> conditions error.
>>>> I use boost::thread for implementating the threads. I have found
>>>> boost_once but I don't know how to use it, so my class properties are
>>>> initialized once.
>>>
>>> http://www.google.com/search?q=boost_once+singleton
>>
>> I know Google and so I've found boost_once, but can you show me a little
>> example?
>
> He was hinting at something, look at the very first result on that Google link.

The first example http://www.boostcookbook.com/Recipe:/1235044 don't
have static members, because
myclass is a class with is a master class of the Singleton. In my class
I've got a static property of the boost mersenne twister and get the
rase condition error on it's get method:

boost::detail::backward_compatible_uniform_01<boost::random::detail::pass_through_engine<boost::random::mersenne_twister<unsigned
int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15,
4022730752u, 18, 3346425566u>&>, double>::operator()()


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