shared - i need it to be useful

Manu turkeyman at gmail.com
Sat Oct 20 06:18:16 UTC 2018


On Fri., 19 Oct. 2018, 3:10 am Walter Bright via Digitalmars-d, <
digitalmars-d at puremagic.com> wrote:

> On 10/17/2018 12:20 AM, Manu wrote:
> > What does it mean 'aliased' precisely?
>
> Aliasing means there are two paths to the same piece of data. That could
> be two
> pointers pointing to the same data, or one pointer to a variable that is
> accessible by name.
>

The reason I ask is because, by my definition, if you have:
int* a;
shared(int)* b = a;

While you have 2 numbers that address the same data, it is not actually
aliased because only `a` can access it. It is not aliased in any practical
sense.

> It doesn't really give us
> > anything in practice that we don't have in C++.
>
> It provides a standard, enforced way to distinguish shared data from
> unshared
> data, and no way to bypass it in @safe code. There's no way to do that in
> C++.
>

Right, but we can do so much better. I want shared to model "what is
thread- at safe to do", because that models what you are able to do, and what
API's should encourage when operating on `shared` things.

Exclusively distinguishing shared and unshared data is not an interesting
distinction if shared data has no access.
I've been trying to say over and over; ignore what you think you know about
that definition, accept my rules strictly as given (they're very simple and
concise, there's only 2 rules), such that shared will mean "is threadsafe
to call with this data" when applied to function args...
Build the thought experiment outward from there.
That's an interesting and useful definition for shared, and it leads to a
framework where shared is useful in a fully @safe SMP program, and even
models @safe transitions across unshared -> shared boundaries (parallel
for, map/reduce, etc, fork and join style workloads), which are typical
lock-free patterns.

Lock-and-cast semantics are preserved unchanged for those that interact in
the way shared is prescribed today, but strictly modeling that workflow is
uninteresting, because it's unsafe by definition. I'm not losing that, but
I'm trying to introduce a safe workflow that exists in complement, and my
model works.
I don't even know if we have a mutex defined in our codebase, we don't use
them... but we can max out a 64core thread ripper.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20181019/edefac8a/attachment.html>


More information about the Digitalmars-d mailing list