Program exiting from thread with infinite loop

Ali Çehreli acehreli at yahoo.com
Fri Jan 19 18:18:31 UTC 2018


On 01/19/2018 09:46 AM, Chris M. wrote:

 > I tried putting an infinite loop inside main() as well, didn't seem to
 > help.

Another reason is an exception thrown in the child thread. If the 
exception is not caught, it will terminate the child thread and the main 
will not know anything about it. I have something about that here:

 
http://ddili.org/ders/d.en/concurrency.html#ix_concurrency.exception,%20concurrency

 > I'm guessing there's probably a better way to make the main thread
 > wait?

std.core.thread_joinAll is a way but you would want to tell the other 
thread to terminate first.

   https://dlang.org/phobos/core_thread.html#.thread_joinAll

So, instead of while(true), try while(someCondition). In that case the 
main thread sets the condition e.g. by sending a message and then joins.

Ali



More information about the Digitalmars-d-learn mailing list