How do I stop a thread immediately, in perl?
Should I use the SIG interrupt or someone show me hints.

10 Years
Discussion Span
Last Post by kararu

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. :-|


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.


I used widget->update; for a particular frame frequently and transfered the variable value immeadiately....
So update refreshes a variable too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.