Shared Classes

Shammah Chancellor anonymous at coward.com
Sat Nov 9 11:26:37 PST 2013


On 2013-11-09 17:12:46 +0000, evilrat said:

> On Saturday, 9 November 2013 at 16:55:18 UTC, S at S.com wrote:
>> It seems to me that the way things are currently implemented that a 
>> class itself has to be specifically made to handle being shared.   That 
>> is to say, I cannot import some general library and do (new shared 
>> LibraryType()) if the class doesn't support all the proper shared 
>> methods.  In order for the class to properly implement the shared 
>> methods, it basically needs to be defined as such:
>> 
>> shared class Foo
>> {
>> 	....
>> }
>> 
>> But now I still need to do shared Foo everywhere I use that class.  
>> This seems a bit off to me.
>> 
>> 
>> R/
>> Shammah
> 
> actually you also need shared methods/memebers, shared works similar to 
> const, so for example look at this:
> so it is just storage specifier like const or immutable. and... ugh, 
> sorry i'm too crappy on teaching people, but i hope you find this 
> example somewhat helpful and someone else could give you more info on 
> this.

I understand how it works right now.  My point is that it's 
dysfunctional.   It's nearly impossible to make a class which can be 
declared as "shared" but also not shared.  It's an all-or-nothing type 
proposition right now the way that implicit casting of shared works.   
Aside from that, if your class has any EXTERNAL dependencies, 
everything breaks:

class Foo {
	Tid childFiber; .... <-- None of STD.concurrencies
}

auto x = new shared Foo(); <-- boom, none of std.concurrency takes shared(Tid).

int[shared Foo] FooSet; <--- boom toHash not implemented for shared(Foo);

class Foo {
	DataType initializationData;
	this( DataType input ) shared {
		initializationData = input; //Does not work as soon as Foo is 
declared is shared.
	}

	this(shared DataType input ) shared {
		initializationData = input;  //Okay, but does not work if new is 
declared as as normally, without the shared keyword.
	}
}



More information about the Digitalmars-d mailing list