Shared Hell
Denis Koroskin
2korden at gmail.com
Wed Oct 28 12:17:46 PDT 2009
On Wed, 28 Oct 2009 20:30:45 +0300, Walter Bright
<newshound1 at digitalmars.com> wrote:
>> Andrei would suggest a Shared!(T) template that would wrap an unshared
>> type and make all methods shared. This would work, but requires full
>> AST manipulation capabilities (it's clearly not enough to just mark all
>> the members shared). What should we do until then?
>
> shared(T) should transitively make a new type where it's all shared.
Type, yes, but not the methods. It will make a type with *no* methods
usable (because they still accept and operate on thread-local variables).
I was hinting about template that would create a separate fully
shared-aware type so that there would be no need for code duplication.
I.e. it would transform the following class:
class Float
{
this(float value) { this.value = value; }
Float opAdd(Float other)
{
return new Vector(this.value + other.value);
}
private float value;
}
into the following:
class SharedFloat
{
this(float value) shared { this.value = value; }
shared Float opAdd(shared Float other) shared
{
return new shared Vector(this.value + other.value);
}
private shared float value;
}
This obviously requires techniques not available in D currently (AST
manipulation).
More information about the Digitalmars-d
mailing list