Sharing in D

JAnderson ask at me.com
Thu Jul 31 22:39:21 PDT 2008


Steven Schveighoffer wrote:
<Snip>
> 
> dmd mycode.d
> Error: when calling foo(shared int *), cannot pass int *
> 
> edit mycode.d, cast to shared int *
> 
> OK, now it works :)  Probably without any problems, because the compiler has 
> no idea whether I'm going to change it in another thread.  Hell, I might not 
> even HAVE more than one thread!
> 
> But the result is, we're back to the same model as before.  And now I have 
> to cast everything.   Annoying.
<Snip>

The idea behind compile-time checking like this is that you can quickly 
identify errors.  If someone writes something in a lib you use that is 
not share safe, you'll know right of the bat.

What you want to do with encapsulation is isolate problems at the point 
at which it occurs, not 5 or 10 classes/functions away when the side 
effect causes finally causes weird behavior.

With a shared policy you'd be able to encapsulate all shared data to 
just the parts of the program that use it.  That way you have only small 
set of places to figure out what went wrong.  Furthermore it provides a 
consistent documentation about how a particular object can be used.

For example if someone suddenly decides that one of their functions can 
only work with sharable memory now and your using a non-shared object 
with it, the compiler will out you when you upgrade that new api and try 
to compile.  If you can't create a shared object or invariant to pass to 
that function then you dam well better know what your doing.

-Joel



More information about the Digitalmars-d mailing list