Multi-Thread message passing approach

Charles Hixson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 16 13:21:49 PDT 2016



On 08/16/2016 07:21 AM, Kagamin via Digitalmars-d-learn wrote:
> On Monday, 15 August 2016 at 01:53:33 UTC, Charles Hixson wrote:
>> If I modify the code to attempt to pass a Tid[] as a member of struct 
>> Start I get:
>>
>> /usr/include/dmd/phobos/std/concurrency.d(603): Error: static assert  
>> "Aliases to mutable thread-local data not allowed."
>> test.d(47):        instantiated from here: send!(Start)
>>
>> and this seems to imply that the casting away of shared might also be 
>> an unsafe access which just doesn't happen to be detected by the 
>> library.
>
> Currently not all types, that are supposed to be thread-safe, support 
> shared, e.g. Semaphore, so it doesn't necessarily mean that sharing 
> them is incorrect.
>
Thanks.  But "not all types" is a bit worrisome.  Fortunately it's just 
as easy to pass a fixed length array of Tids through send, and that even 
yields simpler code.  The problems I was running into turned out to be 
because there was a "local reference", i.e. the dynamic array.  I just 
wasn't understanding the error message.  So now I don't need to use the 
"shared data" that I was worrying about.  I am a bit surprised, however, 
as Tids include a private class reference, and it seems as if that 
should raise the same error flag, but it doesn't.

Of course, the real problem is that just because concurrent software 
seems to be working right when you test it doesn't say anything about 
how it will perform under load...so I want to avoid anything even 
questionable.


More information about the Digitalmars-d-learn mailing list