bug-commoncpp
[Top][All Lists]
Advanced

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

Re: Why is Thread::terminate() protected?


From: Nick Liebmann
Subject: Re: Why is Thread::terminate() protected?
Date: Thu, 5 Aug 2004 09:54:35 +0100

Hi,

Could you not just write your own member function in your derived class?

public:
void do_terminate()
{
    terminate();
}

which you call instead of terminate() from outside.

regards

Nick

Byrial Jensen wrote:
> Hallo,
> 
> I am using threads in CommonC++ and have a situation
> where I want one thread to create another thread and
> later terminate it again. I thougt it would be possible
> to do it as outlined in the example code below:
> 
> class MyThread : public Thread
> {
> public:
> MyThread () {};
> virtual ~MyThread () { terminate (); };
> 
> protected:
> virtual void run ()
> {
> while (1)
> {
> setCancel (cancelImmediate);
> do_something ();
> setCancel (cancelDeferred);
> do_something_else ();
> testCancel ();
> };
> };
> 
> virtual void final () { delete this; };
> };
> 
> int main ()
> {
> MyThread *mt = new MyThread ();
> mt->start ();
> wait_for_something ();
> mt->terminate ();
> wait_again ();
> return 0;
> }
> 
> However, that does not work because Thread::terminate() is
> declared protected. Neither can I just delete my MyThread
> object because then I cannot control that it does not happen
> while cancellation is deferred.
> 
> Would it do any harm just to declare Thread::terminate()
> public, or is there another preferred way to do what I
> intend to do?
> 
> Thank you for your help.
> 
> Best regards
> Byrial Jensen
> 
> 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-commoncpp






reply via email to

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