Boost logo

Boost Users :

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


Am 22.08.2010 um 11:41 schrieb Mathias Gaunard:

> Le 22/08/2010 07:59, Philipp Kraus wrote:
>
>> The first example http://www.boostcookbook.com/Recipe:/1235044 don't
>> have static members,
>
> That doesn't change anything.
> A singleton with static members is kind of pointless though.
>
>
>> because
>> myclass is a class with is a master class of the Singleton.
>
> What is that supposed to mean?
>
>
>> 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()()
>
> I don't understand what this is supposed to mean either.
> Why not attach a testcase showing the problem?

I have written my own random class, in which I use a static
boost::mt19937. On a single thread always works fine, but on
multithread I get race condition errors. So I would like to create a
static member over all threads. My question should be "how can I
create a static member over multithreads". During searching the web
and reading articles, I think it's a bad idea to do that. I have re-
written my class and change the static member to a non-static member.
Now every thread gets his own object and I don't run into race
conditions

Thx

Phil



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