stop thread

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 50
Reputation: kararu is an unknown quantity at this point 
Solved Threads: 0
kararu kararu is offline Offline
Junior Poster in Training

stop thread

 
0
  #1
Oct 18th, 2006
How do I stop a thread immediately, in perl?
Should I use the SIG interrupt or someone show me hints.
thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: stop thread

 
0
  #2
Oct 18th, 2006
do you want to stop a perl thread or a thread in an unrelated process?

the exit command should stop a perl thread. die may kill all threads (although it probably shouldn't?) and kill can be used to kill a process by reference.

http://search.cpan.org/~rgarcia/perl...d/perlfork.pod
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 50
Reputation: kararu is an unknown quantity at this point 
Solved Threads: 0
kararu kararu is offline Offline
Junior Poster in Training

Re: stop thread

 
0
  #3
Oct 18th, 2006
thanks matt,
Actually my program uses perl,Tk.Since Tk didnot workout with perl threads I used inline c++ for threading alone.Now when I press a stop button,I need all running threads to stop.
In c++ we can use a volatile variable.If it was perl threads kill would have helped. Now I have to find a method to transfer stop command from perl to c++ program.
Something like the volatile variable , sig interrupt or so. :-|
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: stop thread

 
0
  #4
Oct 19th, 2006
I had a quick look at some of the Inline package documentation yesterday... It seems like you have an effective equivelent of C++ when you are using the package, so to terminate a C++ process will involve holding reference to the process and terminating it exactly as you would if it were a C++ process.

However, I would assume that terminating the Perl thread that indirectly launched C++ threads (via Inline) would terminate those active C++ threads. If you can't create a new Perl thread that isn't going to help you much anyway, unless you want to terminate the whole program.

Creating a new thread in C++ should give you a process ID; but that will not necessarily be recognised by Perl's kill() method or comparable with a Perl process ID.

Forecefully terminating a thread is platform dependant... I know the Windows API functions but not the *NIX ones.

I would poll a Perl function that returns a finite state (running/active). Then each C++ thread can call that function periodically, check whether it should be running or not, and either die of its own accord or run as it should.

You should be able to pass a Perl function/object pointer to each C++ thread when you create it; using Inline appends certain #includes to the C++ source, includes that allow you to access Perl functions from your C source. Passing a pointer will ensure that you access the function in your running Perl process rather than invoking a new one..

I'd advise reading all parts of the Inline documentation, and any documents that are referenced in that documentation. They certainly will be able to give you more conclusive details about the inner workings/usage of the Inline packages and those C++ includes.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 50
Reputation: kararu is an unknown quantity at this point 
Solved Threads: 0
kararu kararu is offline Offline
Junior Poster in Training

Re: stop thread

 
0
  #5
Oct 25th, 2006
I used widget->update; for a particular frame frequently and transfered the variable value immeadiately....
So update refreshes a variable too.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC