bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Thread::detach() call doesn't return


From: Ian Gough
Subject: RE: Thread::detach() call doesn't return
Date: Mon, 31 Mar 2003 13:20:01 -0500

If you are linking in the older code as a dynamic lib, make sure that it
was compiled with the multithreaded libs.

I don't know if this will help, but I would try fully constructing the
thread object before attempting to start/detach it. Is there a
difference between how your program works using start() instead of
detach()? Try:

 class MyClass1 : public Thread
 {
     void run(void)
     {
         int i = 0;
         while(true)
             if (++i == 0) cout << "Rollover!" << endl;
     };
 
     public:
     MyClass1 (void)
     {
     }
 };
 
 void main(void)
 {
     MyClass1* p1;
 
     p1 = new MyClass1();
     p1.start();
     cout << "MESSAGE" << endl;
     Thread::sleep( 10000 );
 }
 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Nacho de los Ríos Tormo
> Sent: Monday, March 31, 2003 11:00 AM
> To: address@hidden
> Subject: Re: Thread::detach() call doesn't return
> 
> 
> Hello,
> 
> After a week with no replies, I must face the fact that 
> either nobody knows an 
> answer or, more likely, nobody made could make heads nor 
> tails of a poor (and 
> too long) explanation.
> 
> My problem is: sometimes, in my Thread subclasses, the moment 
> I call detach() 
> (whether from the constructor or at a later point), the 
> current thread is 
> permanently lost.
> 
> This only happens when I link in some older code we've got, 
> even if this older 
> code is not called and is left dead.
> 
> This older code is some older single-thread code that runs fine if:
> 
> a)compiled as a single thread program
> b)its original main() function is called from the run()
>   method of a Thread subclass (though in this case control
>   won't return to the calling thread).
> 
> In the example below, when linking the other code, message 
> "MESSAGE" would 
> never get printed; however, not linking that other code, 
> "MESSAGE" would be 
> printed. In both cases, I would get periodic "Rollover!" messages.
> 
> What so toxic might be lurking in the old code that could 
> make this happen? 
> 
> Thanks for your attention,
> 
> Nacho de los Rios.
> 
> ---------------------------------------------------- 
> 
> class MyClass1 : public Thread
> {
>     void run(void)
>     {
>         int i = 0;
>         while(true)
>             if (++i == 0) cout << "Rollover!" << endl;
>     };
> 
>     public:
>     MyClass1 (void)
>     {
>       detach();
>     }
> };
> 
> void main(void)
> {
>     MyClass1* p1;
> 
>     p1 = new MyClass1();
>     cout << "MESSAGE" << endl;
> }
> 
> 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden 
> http://mail.gnu.org/mailman/listinfo/bug-> commoncpp
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]