On 06/12/2017 12:13 AM, Stanislav Blinov wrote:
On Sunday, 11 June 2017 at 19:06:48 UTC, Andrei Alexandrescu wrote:
I tried to eliminate the static shared ~this as follows:

https://github.com/dlang/phobos/pull/5470/commits/a4b2323f035b663727349d390719509d0e3247ba

However, unittesting fails at src/core/thread.d(2042). I suspect it's because the atexit call occurs too late, after the shared static this in src/core/thread.d has already been called.

Thoughts on how to make this work?


Thanks,

Andrei

Which atexit call? The shared static ~this is still present in that commit.

Eh, the link doesn't work anymore; I hoped it would be immutable. Anyhow, I just tried this again:

private final class ParallelismThread : Thread
{
    this(void delegate() dg)
    {
        super(dg);
        static shared bool once;
        import std.concurrency;
        initOnce!once({
            import core.stdc.stdlib;
            atexit(&doThisAtExit);
            return true;
        }());
    }

    TaskPool pool;
}

// Kill daemon threads.
//shared static ~this()
extern(C) void doThisAtExit()
{
    foreach (ref thread; Thread)
    {
        auto pthread = cast(ParallelismThread) thread;
        if (pthread is null) continue;
        auto pool = pthread.pool;
        if (!pool.isDaemon) continue;
        pool.stop();
        pthread.join();
    }
}

There's no more shared static ~this(). Instead, we have an atexit registration. It fails in src/core/thread.d(2042).


Andrei

Reply via email to