The "no gc" crowd

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 9 21:24:20 PDT 2013


On Wednesday, October 09, 2013 20:55:07 Jonathan M Davis wrote:
> On Wednesday, October 09, 2013 20:04:50 Jacob Carlborg wrote:
> > On 2013-10-09 19:10, Andrei Alexandrescu wrote:
> > > Again: USER CODE SHOULD HAVE NO BUSINESS CASTING CASUALLY TO GET WORK
> > > DONE.
> > 
> > I agree. Doesn't "new shared(X)", or something like that, already work?
> 
> That depends. It works with objects I think (for both shared and immutable),
> but you definitely have to cast to immutable if you want an immutable array
> or AA.
> 
> Also, casting _away_ shared is going to be a very common operation due to
> how shared works. In order to use shared, you basically have to protect the
> variable with a mutex or synchronized block, cast away shared, and then use
> it as thread-local for whatever you're doing until you release the lock (in
> which case, you have to be sure that there are no more thread-local
> references to the shared object). As such, while it might be possible to
> construct stuff directly as shared, it's going to have to be cast to
> thread-local just to use it in any meaningful way. So, at this point, I
> don't think that it even vaguely flies to try and make it so that casting
> away shared is something that isn't typically done. It's going to be done
> about as often as shared is used for anything other than very basic stuff.
> 
> As things stand, I don't think that it's even vaguely tenable to claim that
> casting should be abnormal with regards to immutable and shared. There will
> definitely have to be language changes if we want casting to be abnormal,
> and I think that the two main areas which would have to change would be the
> initialization of immutable arrays and AAs (since that outright requires
> casting at this point), and shared would probably have to have a major
> redesign, because it's outright unusable without casting it away.

And given that std.concurrency requires casting to and from shared or 
immutable in order to pass objects across threads, it seems ilke most of D's 
concurrency model requires casting to and/or from shared or immutable. The 
major exception is structs or classes which are shared or synchronized rather 
than a normal object which is used as shared, and I suspect that that's done 
fairly rarely at this point. In fact, it seems like the most common solution 
is to ignore shared altogether and use __gshared, which is far worse than 
casting to and from shared IMHO.

So, it's my impression that being able to consider casting to or from shared 
as abnormal in code which uses shared is a bit of a pipe dream at this point. 
The current language design pretty much requires casting when doing much of 
anything with concurrency.

- Jonathan M Davis


More information about the Digitalmars-d mailing list