Migrating to Shared

Steven Schveighoffer schveiguy at yahoo.com
Thu May 14 06:19:41 PDT 2009

On Thu, 14 May 2009 08:54:21 -0400, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Tue, 12 May 2009 13:47:02 -0400, Walter Bright  
> <newshound1 at digitalmars.com> wrote:
>> I wrote a brief article which should help:
>> http://www.digitalmars.com/d/2.0/migrate-to-shared.html
> Regarding making globals immutable, one other option that was not  
> identified was making it an enum.
> Most of the time, I would think you'd want manifest constants versus  
> immutable globals, as they take up no static space.
> (not any more comments yet, still reading...)

OK, I think there's another thread talking about this, but I was looking  
for the same thing...

There doesn't seem to be a way to convert shared data into a form (call it  
"locked-shared") that then can be used in a function as if it were local  

For example, given that shared is a type constructor, I have to mark  
methods on a class shared in order to call them on a shared class  
instance.  But if there was a way to lock the instance so it temporarly  
became local, then I could call any method (as long as it didn't squirrel  
away a pointer to this).  Are there plans to be able to do something like  
this?  It couldn't be simply marked local, because you don't want to be  
able to squirrel away a pointer to it.  It would have to be marked  
something else...

Then comes the notion of deep locking: if you lock simply the this  
pointer, then it becomes tail-shared as you mentioned -- all the  
references the object contains are still shared.  You'd almost have to  
recursively lock everything, and then what if something has a cycle...

I'm thinking this shared thing is going to be only good for small POD, as  
it's going to be almost untennable to deal with repeating all  
implementation just because something is shared or not.  And even then,  
you probably want to copy the POD to non-shared form so you can pass it  
around.  I don't anticipate anyone making much more than a shared int.


More information about the Digitalmars-d mailing list