Sharing in D

Jason House jason.james.house at gmail.com
Fri Aug 1 11:45:10 PDT 2008


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. 

> 
> 
> > Two, the guarantees for shared data are lost. Code using the
> > non-shared reference will not respect that the variable really is
> > shared.
> 
> That would be true if shared were implicitly cast to unshared, but 
> that's not the case. It's unshared implicitly cast to shared.

I don't see how having one thread with a reference to unshared data and N threads with shared references to the unshared data can work. Maybe the shared references will play nice with each other, but they will mess up assumptions by the unshared code. What am I missing?  



More information about the Digitalmars-d mailing list