Problems with Mutex

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 26 16:13:44 PDT 2014


On Sun, 26 Oct 2014 22:53:07 +0000
Neven via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> Why cannot I globally have auto mutex = new Mutex? And why it 
> works now when I put __gshared?
this is because 'auto mutex = new Mutex' is not a global declaration,
it's thread-local declaration. all D variables are thread-locals by
default.

i.e. you have one indepented Mutex for each thread. and you initialized
it only in one thread, all other threads got unitialized Mutex objects.

having thread-locals instead of globals by default can be confusing if
you missed that in documentation. just use 'shared' or '__gshared' to
get "real" globals.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141027/9d649e6b/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list