Program exiting from thread with infinite loop

Chris M. chrismohrfeld at comcast.net
Fri Jan 19 20:35:14 UTC 2018


On Friday, 19 January 2018 at 18:18:31 UTC, Ali Çehreli wrote:
> 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

I'm not sure what's going on. I've tried all sorts of things from 
your link, it just runs the function once and exits every time. 
There aren't any exceptions being thrown from the thread.

That robot example is basically exactly what I'm doing, and yet 
even that doesn't seem to resolve it.


More information about the Digitalmars-d-learn mailing list