Trying to understand how "shared" works in D

Matej Nanut matejnanut at gmail.com
Thu Jan 31 08:50:50 PST 2013


First of all, "const" is usually used as just a bridge between 
immutable and plain types. You should probably use "immutable" 
there.

As for sharing, immutable variables are implicitly shared, since 
they can never change (const variables CAN change somewhere else 
in the program). Your globalVar gets copied to each of the 
thread's heaps though.  If you change it in one, you won't see 
the difference in the other.


More information about the Digitalmars-d-learn mailing list