[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Why is Thread::terminate() protected?
From: |
Byrial Jensen |
Subject: |
Why is Thread::terminate() protected? |
Date: |
Wed, 4 Aug 2004 14:47:37 +0200 |
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
- Why is Thread::terminate() protected?,
Byrial Jensen <=