Only const or immutable class thread local variables are allowed

qznc qznc at web.de
Mon Dec 9 00:42:05 PST 2013


On Monday, 9 December 2013 at 06:43:05 UTC, Joseph Rushton 
Wakeling wrote:
> On 09/12/13 01:24, Ali Çehreli wrote:
>> On 12/08/2013 02:40 PM, qznc wrote:
>>
>>> I understand you are talking about the "Singleton" design 
>>> pattern.
>>> You might want to look how std.parallelism does it with the 
>>> default
>>> global thread pool.
>>>
>>> https://github.com/D-Programming-Language/phobos/blob/master/std/parallelism.d#L3261
>
> (ii) I still think it's not what I want.  The "static" class 
> instance doesn't need to be globally global, I want the default 
> thread-local storage as per the existing std.random.rndGen.  
> Hence the solution I arrived at, but which I'm sure could be 
> improved.

class Foo {
	private static Foo singleton = null;
	@property public static Foo global() {
		if (singleton is null)
			singleton = new Foo();
		return singleton;
	}
}

Running example: http://www.dpaste.dzfl.pl/f65513fa


More information about the Digitalmars-d-learn mailing list