www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - mutexes (mutices?) and TLS

reply "Torje Digernes" <torjehoa pvv.org> writes:
Compiling the minimal example below with -vtls says a global 
mutex is thread local. Is it supposed to be that way?

dmd v2.064
http://dpaste.dzfl.pl/74f9d635
Dec 02 2013
parent reply Artem Tarasov <lomereiter gmail.com> writes:
Yes, global variables are thread-local by default. Use shared or _gshared
qualifier.
I guess such questions belong to D.learn.
Dec 02 2013
parent reply "Torje Digernes" <torjehoa pvv.org> writes:
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?
Dec 02 2013
next sibling parent reply Shammah Chancellor <anonymous coward.com> writes:
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.
Dec 02 2013
parent reply "eles" <eles eles.com> writes:
On Tuesday, 3 December 2013 at 05:22:20 UTC, Shammah Chancellor 
wrote:
 On 2013-12-02 16:44:24 +0000, Torje Digernes said:

 On Monday, 2 December 2013 at 12:09:34 UTC, Artem Tarasov 
 wrote:
 used a global mutex -- I recently did the same thing.   Knowing 
 about TLS though I declared it as __gshared on the first try
why such an ugly name for this qualifier?
Dec 02 2013
next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Tuesday, 3 December 2013 at 07:48:07 UTC, eles wrote:
 On Tuesday, 3 December 2013 at 05:22:20 UTC, Shammah Chancellor 
 wrote:
 On 2013-12-02 16:44:24 +0000, Torje Digernes said:

 On Monday, 2 December 2013 at 12:09:34 UTC, Artem Tarasov 
 wrote:
 used a global mutex -- I recently did the same thing.   
 Knowing about TLS though I declared it as __gshared on the 
 first try
why such an ugly name for this qualifier?
Because it is dead unsafe.
Dec 03 2013
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 12/3/2013 4:48 PM, eles wrote:
 On Tuesday, 3 December 2013 at 05:22:20 UTC, Shammah Chancellor wrote:
 On 2013-12-02 16:44:24 +0000, Torje Digernes said:

 On Monday, 2 December 2013 at 12:09:34 UTC, Artem Tarasov wrote:
 used a global mutex -- I recently did the same thing.   Knowing about
 TLS though I declared it as __gshared on the first try
why such an ugly name for this qualifier?
Because "here be dragons." __gshared offers no guarantees and no safety. It shouldn't be used carelessly. It was made ugly intentionally.
Dec 03 2013
parent Artem Tarasov <lomereiter gmail.com> writes:
An old thread on this topic:
http://forum.dlang.org/thread/mailman.2017.1353214033.5162.digitalmars-d puremagic.com
Nothing has changed since then.
Dec 03 2013
prev sibling parent luka8088 <luka8088 owave.net> writes:
On 2.12.2013. 17:44, Torje Digernes wrote:
 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?
Take into consideration that shared ( http://dlang.org/migrate-to-shared.html ) has not been fully implemented nor fully documented yet. For more information check out: http://forum.dlang.org/thread/k7orpj$1tt5$1 digitalmars.com
Dec 03 2013