in reply to Re^2: Execute a sub in the background
in thread Execute a sub in the background

You don't have to worry about detached threads when killing the process. They will be taken care of. When a thread started without 'detach'-ing it is still alive when your process is terminated you will get a warning that it exited with unjoined threads. My experience is mainly with Tk: in this case detached threads work fine as far as they never terminate. If they terminate while the MainLoop is still active it will crash miserably. So with Tk I always use infinite while(1){#do processing} style threads.

Replies are listed 'Best First'.
Re^4: Execute a sub in the background
by egzoti4en (Initiate) on Feb 01, 2012 at 15:40 UTC

    I understand that Perl takes care of detached threads, but what if i want to kill at some time in my program before Perl did.

      You can simply return from your thread. (As far as it is not a Tk application.) Normally there is no need to 'kill' a thread.

        Well here is the situatian. As i mentioned the sub in the thread keeps going and my main program also keeps going.

        I want in the main process when i hit a button to stop the cycle in the thread. Is there such way. I mean maybe to use a flag in the sub(tried this it didn't reflect anything). So is there a way to end the cycle in the sub

        This is what i mean by killing it i want to stop this sub or simply execute return in it when there i a button pressed in the main process