shared array?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 11 01:52:34 PDT 2015


On Friday, September 11, 2015 00:50:13 Adam D. Ruppe via Digitalmars-d-learn wrote:
> On Friday, 11 September 2015 at 00:48:28 UTC, Prudence wrote:
> > static Array!(bool delegate(int, WPARAM, LPARAM)) callbacks;
>
> Try just using a regular array instead of the library Array.
>
>
> static bool delegate(int, WPARAM, LPARAM)[] callbacks;
>
> my guess is the Array library thing isn't marked as shared
> internally.

Given how shared works, for a class or struct to work with shared, it pretty
much has to be designed specifically to be used with shared. Depending on
its members, it's possible to declare a variable of class or struct type as
shared and then cast away shared to operate on it (after protecting access
to it with a mutex of course), but actually using an object as shared is
impossible unless the type was specifically designed to be used that way,
and even marking one as shared with the idea that you'll cast away shared to
operate on it (after protecting it with a mutex) probably won't work in many
cases simply because the type's internals weren't designed to work with
shared and could end up with compilation errors even if it was never
actually going to be used without casting away shared.

In general, shared should only be used with built-in types or types which
were specifically designed to be shared, and that means that types that
you'd use in non-shared code aren't going to work in shared code. This can
be annoying, but it really forces you to separate out your shared code from
your normal code, which is arguably a good thing. Still, shared is one of
those things that we need to re-examine and see how it should be changed to
be more usable. It's a great idea, but the devil is in the details.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list