What reasons are known a thread stops suddenly?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 4 14:27:31 PST 2016


On 02/04/2016 12:25 PM, tcak wrote:

 > void threadFunc(){
 >      scope(exit){
 >          writeln("Leaving 2: ", stopRequested);
 >      }
 >
 >
 >      while( !stopRequested ){
 > /* THERE IS NO "RETURN" HERE AT ALL */
 >      }
 >
 >      writeln("Leaving 1: ", stopRequested);
 > }
 >
 >
 >
 > While loop is running, suddenly "Leaving 2: false" is seen.

That would happen when there is an exception.

 > Checked with
 > exception, but there is nothing.

If a thread is terminated with an exception, its stack is unwound and 
unlike the main thread, the program will not terminate. I think this is 
due to an exception.

 > GDB doesn't show any error.

I think putting a break point at exception construction would be helpful 
but it will be simpler to put a try-catch block that covers the entire 
body of threadFunc().

 > There is no
 > "Leaving 1: .." message at all.
 >
 > Is there any known reason for a thread to suddenly stop like this?

I am still betting on an exception. :)

Ali



More information about the Digitalmars-d-learn mailing list