Re: How to properly exit a thread?
- From: Paul Davis <pjdavis engineering uiowa edu>
- To: Xiangfei Jia <xjianz gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: How to properly exit a thread?
- Date: Sun, 14 May 2006 01:09:57 -0500
Xiangfei,
Docs indicate doing something like this:
void
FrameNode::read_new_data()
{
bool done = false ;
while( !done )
{
[do something]
}
throw Glib::Thread::Exit() ;
}
(Although, as a side note, and without looking at the Glib::Thread code
and basing everything off of my guess as to how this is implemented,
throw Glib::Thread::Exit() is optional at the end, and is probably meant
as a way to exit the thread "early". Ie, don't call return ; Maybe
someone with more experience on the Glib::Thread implementation coudl
explain this a bit better, because it seems like an odd choice of
implementation to me.)
What you've probably got at issue is guranteeing that all of your
threads have exited before you attempt to close your program. My guess
is that you've got a thread waiting on a condtion variable when an
attempt to destroy the condition variable is made.
Without any more info on what your thread is doing, I can't really say
much else.
As a side note, if you create your thread as joinable, read->join() will
block until the thread exits. If you need to ensure that a thread has
exited at some point in your software, this would be one method of doing
so. (This is making some assumptions, like the spawned thread was
required to finish before the spawning thread, if that makes any
sense.) The more general method is using one of the normal
synchronization constructs. Ie, a semaphore.
Hope that helps more than it confuses.
Paul
Xiangfei Jia wrote:
I created a thread like this:
Glib::Thread *const read =
Glib::Thread::create(sigc::mem_fun(node, &FrameNode::read_new_data),
false);
Sometimes, when I exit from my program I got this error message:
GThread-ERROR **: file gthread-posix.c: line 247 (): error 'Device or
resource busy' during 'pthread_cond_destroy ((pthread_cond_t *) cond)'
aborting...
Aborted
I looked at the Glib reference, I found out I should use
throw Glib::Thread::Exit <http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Thread_1_1Exit.html>
();
to exit my thread. But I don't really know how to use this properly.
Can anyone tell me how to use it please!!!!!
Thanks in advance!
Fei
------------------------------------------------------------------------
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]