| | |
stop thread
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
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..
•
•
Join Date: Sep 2006
Posts: 50
Reputation:
Solved Threads: 0
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. :-|
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. :-|
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.
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..
![]() |
Similar Threads
- how to kill a thread in python? (Python)
- Stopping a thread... (Java)
- have log !!!!!!!!!!! finally (Viruses, Spyware and other Nasties)
- They don't want us to post (DaniWeb Community Feedback)
- JMF question: question about the unrealized player (Java)
Other Threads in the Perl Forum
- Previous Thread: Matching "pi" but not "pie"
- Next Thread: How do i run perl on windows 98
| Thread Tools | Search this Thread |
Tag cloud for Perl






