std.parallelism.taskPool daemon threads not terminating

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 17 07:29:57 PDT 2016


On Fri, 2016-06-17 at 00:14 +0000, Moritz Maxeiner via Digitalmars-d-
learn wrote:
> So, I am probably overlooking something obvious, but here goes:
> According to my understanding of daemon threads and what is 
> documented here[1],
> this following program should terminate once the druntime shuts 
> down, as the thread working on the task is supposed to be a 
> daemon thread:
> 
> > import std.parallelism;
> > 
> > void main()
> > {
> > 	taskPool.put(task({ while(true) {} }));
> > }
> 
> The actual behaviour (with dmd 2.071 and ldc2 1.0.0), however, is 
> that the program keeps running.

A priori, assuming I am not missing anything, this behaviour seems
entirely reasonable. The task is an infinite loop so it never
terminates. This means the threadpool does not stop working, which
means the program does not terminate.

> In contract, this behaves as expected:
> 
> > import core.thread;
> > 
> > void main()
> > {
> >    with (new Thread({ while(true) {} })) {
> >        isDaemon = true;
> >        start();
> >    }
> > }
> 
> Commenting out setting the isDaemon property will achieve the 
> same behaviour as the taskPool example. Is this the intended 
> behaviour of taskPool (because it does have isDaemon set)?

I suspect that daemon may not mean what you think it means. At least
not with respect to the threadpool.

> 
> [1] https://dlang.org/library/std/parallelism/task_pool.html
-- 

Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20160617/b1c290da/attachment.sig>


More information about the Digitalmars-d-learn mailing list