www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6380] New: Proposal to make 'shared usable

http://d.puremagic.com/issues/show_bug.cgi?id=6380

           Summary: Proposal to make 'shared usable
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: htvennik gmail.com



---
I very much like the idea of the transitive shared attribute in D, but in
practice it turns out to be a real pain in the ass. Just try once to write a
class A that will work fine both as just 'A' and as 'shared(A)'. If you're very
lucky you just have to duplicate all your code in 'shared' methods.

Now think of class A as a container type. Need it be different for A and
shared(A)? Apart from synchronisation, no.

Even Phobos' container types Just Don't Work when marked as shared. But shared
data is usually meant to be used somehow, doesn't it? So here is my proposal
for a solution to most of the trouble:

If a non-static member function is called and the following is all true:
- 'this' is shared
- there is no matching 'shared' overload for the function being called

then do the following:
- search for a matching overload that is not marked as shared
- if found, check it semantically as if it were marked as shared
- if it passes the check, use it, but call it through a synchronisation wrapper

Here, calling through a synchronisation wrapper works like this:

// Assuming:
shared(A) a = cast(shared) new A();

// The following …
a.foo()

// … will expand to:
synchronized(a) { a.foo() }

Feel free to comment!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2011