What exactly shared means?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 2 16:12:23 PST 2015


On Friday, January 02, 2015 23:51:04 John Colvin via Digitalmars-d-learn wrote:
> AFAIK, the only data in D that the compiler is allowed to assume
> to be thread-local is data that it can prove is thread-local. The
> trivial case is TLS, which is thread-local by definition.

In D, if a type is not marked as shared, then it is by definition
thread-local, and the compiler is free to assume that it's thread-local. If
it's not actually thread-local (e.g. because you cast away shared), then
it's up to you to ensure that no other threads access that data while it's
being referred to via a reference or pointer that's typed as thread-local.
The only exception is immutable, in which case it's implicitly shared,
because it can never change, and there's no need to worry about multiple
threads accessing the data at the same time.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list