digitalmars.D - One for experts in std.parallelism
- Andrei Alexandrescu (8/8) Jun 11 2017 I tried to eliminate the static shared ~this as follows:
- Stanislav Blinov (4/12) Jun 11 2017 Which atexit call? The shared static ~this is still present in
- Andrei Alexandrescu (35/53) Jun 12 2017 Eh, the link doesn't work anymore; I hoped it would be immutable.
- Stanislav Blinov (10/66) Jun 12 2017 To me, it feels like the options are:
- Andrei Alexandrescu (2/5) Jun 12 2017 Thanks! -- Andrei
- Vladimir Panteleev (3/9) Jun 12 2017 https://github.com/andralex/phobos/commit/a4b2323f035b663727349d39071950...
- Moritz Maxeiner (6/12) Jun 12 2017 Obligatory reminder that the static shared ~this you are trying
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
Jun 11 2017
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, AndreiWhich atexit call? The shared static ~this is still present in that commit.
Jun 11 2017
On 06/12/2017 12:13 AM, Stanislav Blinov wrote:On Sunday, 11 June 2017 at 19:06:48 UTC, Andrei Alexandrescu wrote: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). AndreiI tried to eliminate the static shared ~this as follows: https://github.com/dlang/phobos/pull/5470/commits/a4b2323f035b66372734 d390719509d0e3247ba 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, AndreiWhich atexit call? The shared static ~this is still present in that commit.
Jun 12 2017
On Monday, 12 June 2017 at 14:21:29 UTC, Andrei Alexandrescu wrote:On 06/12/2017 12:13 AM, Stanislav Blinov wrote:To me, it feels like the options are: 1. Take a performance hit and unregister "parallel" threads from the runtime at creation, and keep a separate lock-protected list. 2. Modify runtime to allow creating unregistered Threads 3. Push thread_term() call back if at all possible (i.e. by also registering it with atexit). I'll put the PR for (1) up for discussion a bit later. (2) and (3) I'll need to dig into runtime somewhat first.On Sunday, 11 June 2017 at 19:06:48 UTC, Andrei Alexandrescu wrote: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). AndreiI 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, AndreiWhich atexit call? The shared static ~this is still present in that commit.
Jun 12 2017
On 06/12/2017 01:43 PM, Stanislav Blinov wrote:I'll put the PR for (1) up for discussion a bit later. (2) and (3) I'll need to dig into runtime somewhat first.Thanks! -- Andrei
Jun 12 2017
On Monday, 12 June 2017 at 14:21:29 UTC, Andrei Alexandrescu wrote:On 06/12/2017 12:13 AM, Stanislav Blinov wrote:https://github.com/andralex/phobos/commit/a4b2323f035b663727349d390719509d0e3247baOn Sunday, 11 June 2017 at 19:06:48 UTC, Andrei Alexandrescu wrote:Eh, the link doesn't work anymore; I hoped it would be immutable.https://github.com/dlang/phobos/pull/5470/commits/a4b2323f035b663727349d390719509d0e3247ba
Jun 12 2017
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?Obligatory reminder that the static shared ~this you are trying to port is buggy[1] and any of std.parallelism's alleged "daemon" threads being busy in reality keeps the program from terminating. [1] https://issues.dlang.org/show_bug.cgi?id=16324
Jun 12 2017