default random object?

grauzone none at example.net
Sat Feb 14 10:19:11 PST 2009


Walter Bright wrote:
> grauzone wrote:
>> I don't understand this. If implemented right (D2.0 or gcc thread 
>> variables), TLS can be as fast as a normal global variable. You only 
>> need an additional check (a simple if()) to lazily initialize the RNG.
> 
> That's the notorious double-checked-locking bug, an incredibly seductive 
> pattern that is wrong and very illustrative about how hard it is to do 
> multithreaded programming correctly.
> 
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

No, I meant something like this:

thread RandomGenerator rng;

if (!rng) {
	rng = new RandomGenerator();
}



More information about the Digitalmars-d mailing list