You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stanislav.blinov commented on 2014-02-11T15:07:00Z
This is an interesting request.
TDPL states that any ref passing (explicit or implicit) into spawn should be prohibited, except for immutable. However, current implementation of spawn does allow passing pointers to shared. But if we can pass pointers, why aren't we able to pass by ref?
This:
void func(shared int* p) {}
shared int i;
spawn(&func, &i);
is no more safer than this:
void func(ref shared int p) {}
shared int i;
spawn(&func, i);
or even this:
struct Foo { shared int* p; }
void func(Foo foo) {}
shared int i;
spawn(&func, Foo(&i));
Granted, as you've pointed out, without proper care all of those are "Hello, Segfault!", but how else then to pass around shared data without resorting to global variables?
ref propagation could be implemented rather easily (I've done this for my custom thread spawner). It can even be made a bit more involving for the user (e.g. require to create a NullableRef first, a-la C++):
auto nref(ref T v) { return NullableRef!T(&v); }
spawn(&func, i.nref);
The question is how legal this is. Perhaps Andrei and Sean could shed some light on this?
I myself voting for this enhancement.
john.loughran.colvin (@John-Colvin) reported this on 2013-07-23T09:21:43Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=10704
CC List
Description
The text was updated successfully, but these errors were encountered: