Something needs to happen with shared, and soon.
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sun Nov 11 13:10:00 PST 2012
On Sunday, 11 November 2012 at 19:28:30 UTC, Andrej Mitrovic
wrote:
> On 11/11/12, Alex Rønne Petersen <alex at lycus.org> wrote:
>> And finally, the worst part of all of this? People writing
>> code that
>> uses shared today are blindly assuming it actually does the
>> right thing.
>> It doesn't.
>
> I think most people probably don't even use shared due to
> lacking
> Phobos support. E.g.
> http://d.puremagic.com/issues/show_bug.cgi?id=7036
>
> Not even using the write functions worked on shared types until
> 2.059
> (e.g. printing shared arrays).
>
> 'shared' has this wonderfully attractive name to it, but
> apparently it
> doesn't have much guarantees? E.g. Walter's comment here:
> http://d.puremagic.com/issues/show_bug.cgi?id=8077#c1
>
> So +1 from me just because I have no idea what shared is
> supposed to
> guarantee. I've just stubbornly used __gshared variables because
> std.concurrency.send() doesn't accept mutable data. send()
> doesn't
> work with shared either, so I have no clue.. :)
Fix support for shared(T) in std.variant, and you will have fixed
send() as well. Meanwhile, in common cases a simple wrapper
struct suffices.
##################################################
module toy;
import std.concurrency, std.stdio;
struct SImpl {
string s;
int i;
}
alias shared( SImpl ) S;
struct Msg { S s; }
struct Quit {}
S global = S( "global", 999 );
void main () {
auto child = spawn( &task );
S s = S( "abc", 42 );
child.send( Msg( s ) );
child.send( Msg( global ) );
child.send( Quit() );
}
void task () {
bool sentinel = true;
while ( sentinel ) {
receive(
( Msg msg ) { writeln( msg.s.s, " -- ", msg.s.i ); },
( Quit msg ) { sentinel = false; }
);
}
}
##################################################
grant at aesgard ~/Projects/D/foo/shared_test $ dmd toy && ./toy
abc -- 42
global -- 999
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list