To share or not to share, this is the question.

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Mon Oct 17 05:59:13 PDT 2011


Ok, but if i declared a member of type v it should be shared, right?
since i'd essentially declare it to be void*, which gets the enclosing
class's shared attribute.
This is what i did for a class, that contains a HWND member. But the
std.concurrency.spawn function flipped me off and said, that i'm not
supposed to send over an object with unshared aliases.
What's the logic behind this? the HWND should be shared.

I know, i already found out, that HWND is strictly single-threaded,
but the point here is to understand why does the spawn function think
it's unshared.

On Mon, Oct 17, 2011 at 4:45 PM, Dmitry Olshansky <dmitry.olsh at gmail.com> wrote:
> On 17.10.2011 14:24, Gor Gyolchanyan wrote:
>>
>> The shared keyword makes it's user regret ever trying to use it.
>> This keyword has a single purpose: it generates frustration at
>> compile-time.
>> Enough with the emotions.
>> I'm trying to make a Win32 multi-threaded warpper, which allows to
>> efficiently create Win32 windows, that immediately start processing
>> their messages in a separate thread (which will eventually get
>> migrated into a thread pool).
>> As i was trying to deal with the shared-ness, i found out about this:
>>
>> shared class T
>> {
>>        alias void* v;
>
> I guess the problem is here: v is void * and not shared at all. Alias is not
> affected by outer shared decl, shared applies only to members: fields and
> functions. In a sense, an alias is merely using the same name scope.
> Imagine if you semantics (i.e. shared affects aliases) worked, then how
> would you declare a *not* shared type alias inside of it ?
> This won't work:
>        alias Unqual!(void*) v;
>
> --
> Dmitry Olshansky
>


More information about the Digitalmars-d mailing list