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

Well this worked excellent $thr = threads->create(\&status_line)->detach;.

Thank you very much for this advice.

Is there a way after the thread is detached to kill the process ?

Replies are listed 'Best First'.
Re^3: Execute a sub in the background
by chessgui (Scribe) on Feb 01, 2012 at 15:36 UTC
    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.

      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.