Search code examples
thread-safetyconstantsimmutabilitydshared-memory

Shared global immutable objects in D


Is it safe to make a global (module scope) immutable object shared? Should I use shared or __gshared (as it seems for me safe too)?


Solution

  • https://dlang.org/articles/migrate-to-shared.html says:

    Immutable data doesn't have synchronization problems, so the compiler doesn't place it in TLS.

    ("TLS" is thread local storage.)

    So, it does not matter whether the immutable object is declared as shared.

    For brevity, we can omit shared in this case.