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

Reply via email to