Only const or immutable class thread local variables are allowed

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 9 21:33:44 PST 2013


On Monday, December 09, 2013 06:19:19 Joseph Rushton Wakeling wrote:
> On Monday, 9 December 2013 at 00:24:44 UTC, Ali Çehreli wrote:
> > David Simcha presented it as a D-specific pattern and explained
> > how D avoids at least one of the bugs of double-checked locking:
> > 
> > 
> > http://www.youtube.com/watch?feature=player_detailpage&v=yMNMV9JlkcQ#t=167
> > 6
> 
> I will look at this in detail but instinctively based on what I
> understand a singleton to be for, I'm not sure it's what I want:
> I'm not looking for something truly global, only thread-global.

It's still essentially a singleton - it's just that it's a single instance per 
thread in that case instead of per program. And you avoid all of the 
threading-related initialization issues with singletons if it's thread-local. 
Just check whether it's null, initialize it if it is (leave it alone if it 
isn't), and then do whatever you're going to do with it.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list