digitalmars.D - assert or execption case program hang in multi thread
- "liyu" <yunwind msn.com> Feb 20 2009
- "Denis Koroskin" <2korden gmail.com> Feb 21 2009
- "liyu" <yunwind msn.com> Feb 21 2009
- Christopher Wright <dhasenan gmail.com> Feb 21 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Feb 21 2009
- "liyu" <yunwind msn.com> Feb 21 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Feb 21 2009
- Qian Xu <quian.xu stud.tu-ilmenau.de> Feb 24 2009
code as below, assert can't terminate the program when main thread is
running, is it a bug or i miss something?
import tango.core.Thread;
void test()
{
while(1) {
assert(false);
//throw new Exception("test");
}
}
void main() {
auto thread = new Thread(&test);
thread.start();
//if i remove the 3 lines below, then every thing work as expected
while(1) {
Thread.sleep(100); }
}
Feb 20 2009
On Sat, 21 Feb 2009 10:38:40 +0300, liyu <yunwind msn.com> wrote:code as below, assert can't terminate the program when main thread is running, is it a bug or i miss something? import tango.core.Thread; void test() { while(1) { assert(false); //throw new Exception("test"); } } void main() { auto thread = new Thread(&test); thread.start(); //if i remove the 3 lines below, then every thing work as expected while(1) { Thread.sleep(100); } }
I believe it is an expected behaviour. You second thread (which you create explicitly) is throwing an exception and thus gets terminated. You main thread, however, continues to live. What you call 'hang' is your code which sleeps in an infinite loop: while(1) { Thread.sleep(100); } Try putting some stuff into in (like, Stdout('!');) and you'll see that your thread didn't hang, it works perfectly. If you remove the while (1) { Thread.sleep(100); }, your main thread quickly reachs the end of the main() and also gets terminated. Your program finishs its execution when *all* your threads stop.
Feb 21 2009
maybe i should title it assert or execption can't terminate the prog in multithread:-) yes, the main thread is still running, but i want the program terminated when a assert failure or exception happened whatever. otherwise i have to notify the main thread, i think that's a littel inconvenient. "liyu" <yunwind msn.com> wrote in message news:gnob29$1hcd$1 digitalmars.com...code as below, assert can't terminate the program when main thread is running, is it a bug or i miss something? import tango.core.Thread; void test() { while(1) { assert(false); //throw new Exception("test"); } } void main() { auto thread = new Thread(&test); thread.start(); //if i remove the 3 lines below, then every thing work as expected while(1) { Thread.sleep(100); } }
Feb 21 2009
liyu wrote:maybe i should title it assert or execption can't terminate the prog in multithread:-) yes, the main thread is still running, but i want the program terminated when a assert failure or exception happened whatever. otherwise i have to notify the main thread, i think that's a littel inconvenient.
You could make a feature request for Tango. That's where the issue lies.
Feb 21 2009
On Sat, Feb 21, 2009 at 9:04 AM, Christopher Wright <dhasenan gmail.com> wrote:liyu wrote:maybe i should title it assert or execption can't terminate the prog in multithread:-) yes, the main thread is still running, but i want the program terminated when a assert failure or exception happened whatever. otherwise i have to notify the main thread, i think that's a littel inconvenient.
You could make a feature request for Tango. That's where the issue lies.
It might not even be necessary. tango.core.Exception has a way to replace the default assertion handler so that you can i.e. stop all threads when an assertion fails.
Feb 21 2009
yup, that's what i need, thanks all for the reply! "Jarrett Billingsley" <jarrett.billingsley gmail.com> wrote in message news:mailman.813.1235235089.22690.digitalmars-d puremagic.com...On Sat, Feb 21, 2009 at 9:04 AM, Christopher Wright <dhasenan gmail.com> wrote:liyu wrote:maybe i should title it assert or execption can't terminate the prog in multithread:-) yes, the main thread is still running, but i want the program terminated when a assert failure or exception happened whatever. otherwise i have to notify the main thread, i think that's a littel inconvenient.
You could make a feature request for Tango. That's where the issue lies.
It might not even be necessary. tango.core.Exception has a way to replace the default assertion handler so that you can i.e. stop all threads when an assertion fails.
Feb 21 2009
On Sat, Feb 21, 2009 at 7:54 PM, liyu <yunwind msn.com> wrote:yup, that's what i need, thanks all for the reply!
Yay!
Feb 21 2009
liyu wrote:code as below, assert can't terminate the program when main thread is running, is it a bug or i miss something? import tango.core.Thread; void test() { while(1) { assert(false); //throw new Exception("test"); } } void main() { auto thread = new Thread(&test); thread.start(); //if i remove the 3 lines below, then every thing work as expected while(1) { Thread.sleep(100); } }
you should write thread.join() instead of Thread.sleep(100); the syntax might be incorrect. search "join" in the thread class in tango. have a nice day ^^) -- Xu, Qian (stanleyxu) http://stanleyxu2005.blogspot.com
Feb 24 2009









"Denis Koroskin" <2korden gmail.com> 