One for experts in std.parallelism
Stanislav Blinov via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 12 10:43:18 PDT 2017
On Monday, 12 June 2017 at 14:21:29 UTC, Andrei Alexandrescu
wrote:
> 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
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.
More information about the Digitalmars-d
mailing list