How to initialize a globle variable nicely and properly?
Neia Neutuladh
neia at ikeran.org
Sat Dec 15 03:48:15 UTC 2018
On Sat, 15 Dec 2018 02:54:55 +0000, Heromyth wrote:
> shared static this() {
> writeln("running A in shared static this(),
> sharedField=", sharedField);
>
> Thread th = new Thread(() { });
> th.start();
When you start a D thread, thread-local static constructors get run. So
don't start threads until your shared static constructors finish.
If I encountered something like this, I would set up a queue of actions to
be run at the start of main() and fill them with static constructors.
Instead of this static constructor creating a thread, it would enqueue a
delegate that starts the thread.
More information about the Digitalmars-d-learn
mailing list