[Issue 4419] __gshared static in class has no effect

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 03:34:08 PDT 2013


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


Rory <rjmcguire at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rjmcguire at gmail.com


--- Comment #8 from Rory <rjmcguire at gmail.com> 2013-09-13 03:34:04 PDT ---
(In reply to comment #6)
> I agree that __gshared should imply static.  I was very surprised to find this
> was not how it works.

There is no way that shared and static are the same. is __gshared so different
from shared?

sometimes I need to make a class member shared so that any thread can
read/write to it, but I need the class to have multiple instances.

The exact example is a class that contains a threadsafe queue which multiple
threads wait for new tasks by reading and multiple threads add new tasks.
I'd hate to have to always make these static.

Whats interesting about dmd.2.063.2 is that the below makes a shared instance
per class:
class MyClass {
    shared chan!bool ready;
    this() {
        ready = makeChan!bool(1);
    }
}
BUT:
class MyClass {
    shared chan!bool ready = makeChan!bool(1);
}

creates a static instance which is shared amoungst all classes and sub classes.

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


More information about the Digitalmars-d-bugs mailing list