Sharing in D

JAnderson ask at me.com
Sat Aug 2 13:13:16 PDT 2008


Sean Kelly wrote:
> == Quote from Jason House (jason.james.house at gmail.com)'s article
>> Walter Bright Wrote:
>>> Jason House wrote:
>>>> Walter Bright Wrote:
>>>>
>>>>> Unshared can be implicitly cast to shared, so you shouldn't have
>>>>> to.
>>>> That should not be implicit.
>>>>
>>>> For one, thread-local garbage collection of non-shared data would
>>>> leave dangling references to garbage memory.
>>> True, but the memory allocation system shouldn't be (and isn't) built
>>> that way.
>> I don't see how memory allocation fits into it. It's about deallocation and garbage collection. I believe
> the single-threaded garbage collection would only scan memory for the thread in question and would
> miss shared data's reference to non-shared data.
> 
> I think the only way this can work is if you make 'shared' a bit like 'pure' in that a shared
> object can't reference non-shared data.  Then you have a full-on "stop the world" GC for
> the shared data area.  With this approach you'd at least know that most of your GC cycles
> would be thread-local, which is better than none of them.  If the user wants to bypass
> this they can always cast unshared to shared when assigning a shared reference to it.
> This gets back to what I said about shared being transitive.  The sticky part would be
> enforcing it--I guess you'd have to do so at the point of assignment:
> 
>    class C
>     {
>         int* x;
>         shared void put( int* y )
>         {
>             x = y; // error, y is not "shared(int*)"
>         }
>     }
> 
> It really is a lot like const, isn't it?
> 
> 
> Sean

My thought was you could use Ref counting for shared memory and mark and 
  sweep for unshared.

-Joel



More information about the Digitalmars-d mailing list