constructing module level immutable variables at runtime?
Sönke Ludwig via Digitalmars-d
digitalmars-d at puremagic.com
Sun Feb 21 23:09:32 PST 2016
Am 22.02.2016 um 07:55 schrieb Danni Coy via Digitalmars-d:
> I am trying to port a heavily multithreaded C++ application to D.
>
> I have a lot of variables that are set once from a config file at
> runtime and then never change.
> It seems that something like the following would be a very clean design.
>
> module config;
>
> static this()
> {
> num_triggers = to!int(getValueFromConfigFile());
> }
>
> private:
> immutable(int) num_triggers = void;
>
> Is there any reason that allowing this would be a bad idea?
>
This actually works already, if you use "shared static this". "static
this" is invoked for each thread that is started, thus it would
overwrite the existing value of num_triggers, potentially multiple times.
More information about the Digitalmars-d
mailing list