Re: Threads and Gtk2
- From: zentara <zentara zentara net>
- To: gtk-perl-list gnome org
- Subject: Re: Threads and Gtk2
- Date: Thu, 20 Oct 2005 12:28:58 -0400
On Thu, 20 Oct 2005 12:00:43 -0400 (EDT)
gtk-perl-list-request gnome org wrote:
Message: 1
Date: Wed, 19 Oct 2005 11:28:49 -0700
From: Javier Godinez <godinezj gmail com>
Subject: Threads and Gtk2
To: gtk-perl-list gnome org
Message-ID:
<39e231050510191128l132ae054q9cce2fbe138973be mail gmail com>
Content-Type: text/plain; charset=ISO-8859-1
Hello,
Is there a way to gracefully stop a thread from a Gtk2 callback by
using a global?
I am not sure how to get out of the running thread as shown here:
#############################
Any help will be greatly appreciated...
Thanks, Javier Godinez
I will just mention 1 other little detail, which can cause messages
like "a thread exited while 1 other was running".
Before a thread can be joined, it must go to the end of it's code-block.
So this is the basic thread model I use, where shared variables control
the sleeping and dieing of the thread. I know goto's are currently out of favor,
but it is a pretty useful here.
sub work{ #the thread code block
$|++;
while(1){
if($thread{'die'} == 1){goto END }
if ( $thread{'go'} == 1 ){
#do your stuff here in a loop and sprinkle the code with
# if($thread{'go'} == 0){last}
# if($thread{'die'} == 1){goto END}
# in case you need to kill the thread or current code run
# during a long running process
$thread{'go'} = 0; #turn off self before returning
}else
{ sleep 1 }
}
END:
}
#####################################################################
then when you want to exit your app, you can do
sub clean_exit{
$thread{'die'} = 1;
$thread->join;
exit;
}
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]