mutexes (mutices?) and TLS

Shammah Chancellor anonymous at coward.com
Mon Dec 2 21:22:19 PST 2013


On 2013-12-02 16:44:24 +0000, Torje Digernes said:

> On Monday, 2 December 2013 at 12:09:34 UTC, Artem Tarasov wrote:
>> Yes, global variables are thread-local by default. Use shared or _gshared
>> qualifier.
>> I guess such questions belong to D.learn.
> 
> Is this really desired behaviour for mutexes? Since mutexes (per my 
> rather little experience) is mostly used for locking between threads, 
> which is not doable without extra qualifiers now.
> 
> I know that global variables are thread local, but using the mutex in 
> different threads, which seems to be their main usage, require extra 
> qualifiers. Shouldn't the main usage be possible using default setup, 
> as in no extra qualifiers?

I don't think muticies should be turned into some special object that 
don't obey TLS default rules.   If you do pass an object between 
threads, it's mutex will be used appropriately (eg, via send/receive).  
 You're running into this because you used a global mutex -- I recently 
did the same thing.   Knowing about TLS though I declared it as 
__gshared on the first try and it worked.    It is a bit of a gotcha 
though.



More information about the Digitalmars-d mailing list