[dmd-concurrency] tail-shared by default?

Steve Schveighoffer schveiguy at yahoo.com
Sat Jan 9 19:25:18 PST 2010





----- Original Message ----
> From: Walter Bright <walter at digitalmars.com>
> To: Discuss the concurrency model(s) for D <dmd-concurrency at puremagic.com>
> Sent: Sat, January 9, 2010 2:36:34 AM
> Subject: Re: [dmd-concurrency] tail-shared by default?
> 
> 
> 
> Steve Schveighoffer wrote:
> > I think the idea is sound because you *must* pass a pointer to shared data 
> into a function, you can't actually pass the real data, so the pointer itself 
> that lives on the stack should *never* be shared, it's always thread local.  
> Sharing stack data would be more of a pending disaster in my opinion, since 
> stack data is deallocated at will by returning from a function!
> > 
> >  
> 
> Think about passing a local by reference to another function, i.e. ref 
> parameters.

nuts, this looks like the kryptonite of my idea.  A ref to a global class reference which requires shared semantics is indistinguishable from a ref to a local class reference which would require no shared semantics.

However, all is not lost, it can still be resolved, but requires some odd rules.

The two rules are:

1. A thread-local or stack variable marked as shared does not use shared semantics for the actual stack or local data (referenced data does have shared semantics).
2. You cannot take the address of a shared thread local or stack variable.  However, you can take the address of a tail-shared variable.

The second rule sucks, but it's there because once you take the address you cannot distinguish it from a truly shareable type that is allocated on the heap or is a global.

> If I understood you correctly, you are not talking about adjusting the type, but 
> about having something not be shared because it's a local. Having special case 
> rules often sound good, but later turn out to have unforeseen consequences (C++ 
> is full of them). They are best avoided as much as possible.

It sounds like you are not going to accept this, no matter what I say, so I'll drop it.  I will say that if the end result of shared is that the compiler allows sharing stack data, and uselessly puts shared semantics around stack data, it will be a very disappointing result, and I wouldn't tout it as a feature for D.  Sharing stack data without casting should always be illegal.

-Steve



      


More information about the dmd-concurrency mailing list