shared - i need it to be useful
aliak
something at something.com
Thu Oct 18 21:51:52 UTC 2018
On Thursday, 18 October 2018 at 18:12:03 UTC, Stanislav Blinov
wrote:
> On Thursday, 18 October 2018 at 18:05:51 UTC, aliak wrote:
>
>> Right, but the argument is a shared int*, so from what I've
>> understood... you can't do anything with it since it has no
>> shared members. i.e. you can't read or write to it. No?
>
> Obviously the implementation would cast `shared` away, just
> like it would if it were Atomic!int. But for some reason, Manu
> thinks that latter is OK doing that, but former is voodoo. Go
> figure.
Sounds like one is encapsulated within a box that carefully
handles thread safety and makes promises with the API and the
other is not.
I don't think you can apply shared on a free function, i.e.:
void increment(shared int*) shared;
in which case increment would not, and cannot be a threadsafe api
in Manu's world.
So once you throw an Object in to shared land all you could do is
call shared methods on it, and since they'd have been carefully
written with sharing in mind... it does seem a lot more usable.
On these two cases:
increment(shared int* p1) {
// I have no guarantees that protecting and accessing p1 will
not cause problems
//
// but you don't have this guarantee in any world (current nor
MP) because you can
// never be sure that p1 was not cast from a mutable.
}
int* p2;
increment(p2);
// I have no guarantee that accessing p2 is safe anymore.
//
// But that would apply only if the author of increment was being
unsafe.
// and "increment" cannot be marked as shared.
More information about the Digitalmars-d
mailing list