Only const or immutable class thread local variables are allowed

2013-12-08 Thread Joseph Rushton Wakeling
Hello all, I have a challenge, which is this: I'd like to have a public property which will return a reference to an internally stored class instance. ref MyClass myProperty() @property { ... } However, this runs into a problem: I can't use "static" to internally store a

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread Ali Çehreli
On 12/08/2013 10:00 AM, Joseph Rushton Wakeling wrote: > I have a challenge, which is this: I'd like to have a public property > which will return a reference to an internally stored class instance. > > ref MyClass myProperty() @property > { > ... > } First, the usual que

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread Joseph Rushton Wakeling
On 08/12/13 21:12, Ali Çehreli wrote: In any case, I think class static this is the solution: I think I may have misled you by talking about properties, because I _don't_ mean a property of a class. I mean a public standalone function that is marked as a @property, which returns a persistent

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread qznc
On Sunday, 8 December 2013 at 21:32:35 UTC, Joseph Rushton Wakeling wrote: On 08/12/13 21:12, Ali Çehreli wrote: In any case, I think class static this is the solution: I think I may have misled you by talking about properties, because I _don't_ mean a property of a class. I mean a public s

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread Ali Çehreli
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 David Simcha pres

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread Joseph Rushton Wakeling
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=1676 I will look at this in d

Re: Only const or immutable class thread local variables are allowed

2013-12-08 Thread Joseph Rushton Wakeling
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/

Re: Only const or immutable class thread local variables are allowed

2013-12-09 Thread qznc
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 t

Re: Only const or immutable class thread local variables are allowed

2013-12-09 Thread Jonathan M Davis
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.you

Re: Only const or immutable class thread local variables are allowed

2013-12-09 Thread Joseph Rushton Wakeling
On 10/12/13 06:33, Jonathan M Davis wrote: 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

Re: Only const or immutable class thread local variables are allowed

2013-12-09 Thread Jonathan M Davis
On Tuesday, December 10, 2013 08:41:25 Joseph Rushton Wakeling wrote: > On 10/12/13 06:33, Jonathan M Davis wrote: > > 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 initia

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread Joseph Rushton Wakeling
On 10/12/13 08:44, Jonathan M Davis wrote: Yeah. Something like that. What I like is that it actually comes out slightly nicer than the existing code -- you don't need an extra static boolean to check if the RNG has been initialized. This experience is proving typical of class-based RNG and

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread Jonathan M Davis
On Tuesday, December 10, 2013 09:13:12 Joseph Rushton Wakeling wrote: > On 10/12/13 08:44, Jonathan M Davis wrote: > > It's a matter of what you can directly initialize a non-local variable > > with. Module-level variables, static variables, and member variables all > > have to be known at compile

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread Joseph Rushton Wakeling
On 10/12/13 09:27, Jonathan M Davis wrote: A lot of dmd's error messages aren't great. Would this be better? Cannot initialize thread-local class variable %s with a mutable value. Only const or immutable initial values are allowed (e.g. null). That would be better. https://github.com

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread qznc
On Tuesday, 10 December 2013 at 09:50:56 UTC, Joseph Rushton Wakeling wrote: On 10/12/13 09:27, Jonathan M Davis wrote: A lot of dmd's error messages aren't great. Would this be better? Cannot initialize thread-local class variable %s with a mutable value. Only const or immutable initia

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread qznc
On Tuesday, 10 December 2013 at 09:50:56 UTC, Joseph Rushton Wakeling wrote: On 10/12/13 09:27, Jonathan M Davis wrote: A lot of dmd's error messages aren't great. Would this be better? Cannot initialize thread-local class variable %s with a mutable value. Only const or immutable initia

Re: Only const or immutable class thread local variables are allowed

2013-12-10 Thread Joseph Rushton Wakeling
On 10/12/13 11:31, qznc wrote: The changelog is partially generated from Bugzilla issues. That was the main reason to also add issues for pull request, afaik. Fair enough :-) https://d.puremagic.com/issues/show_bug.cgi?id=11714