in reply to Re: how can I detach a thread from another or how can I set a timer for a thread?
in thread how can I detach a thread from another or how can I set a timer for a thread?

Sorry, I misunderstand detach(). Actually, what I want is terminating $thr_1 when time's up in $thr_2

I have to write it with an old perl version v5.8.8 built for x86_64-linux-thread-multi. So there is no exit() or kill() available in the module.

  • Comment on Re^2: how can I detach a thread from another or how can I set a timer for a thread?

Replies are listed 'Best First'.
Re^3: how can I detach a thread from another or how can I set a timer for a thread?
by zentara (Cardinal) on Nov 11, 2011 at 10:17 UTC
    Sorry, I misunderstand detach()

    When a thread reaches the end of it's code block, or is issued a return, it sits and waits with it's return values, for the main thread to join it back in. When you detach the thread, the main thread no longer keeps count of it, and dosn't wait around for any return values. When a detached thread ends, it just goes away, instead of sitting there waiting to be joined.

    If you are using the old 5.8.8 version of threads, you will have to do a bit more work, because, as you say, many thread methods are missing in 5.8.8. You will have to rely on older hacks and work-arounds, for instance see Re: Backticks and SIGALRM


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Yes, the difference is whether or not you care about the final status (return code, etc.) of the thread.   If you do, it sits as a sort of “zombie” until you join it.   (The zombie status exists so that you can rendezvous without encountering race-conditions etc. ...)   If you don’t care, you can just detach the thread and it will perish on its own.

      Thanks a lot, it works for me. May I bother you with another question? I saw some code like:

      $pid = open my $fh, "$cmd |" or die "$!, $^E";

      Could you please tell me what does it mean by '$^E'

      I google it, but nothing useful.

        It's a built-in error message. Read perldoc perlvars and read the section on Error Variables. Its says:
         $EXTENDED_OS_ERROR
               $^E     Error information specific to the current operating system. At the moment, this differs from $! under only VMS, OS/2, and
                       Win32 (and for MacPerl). On all other platforms, $^E is always just the same as $!.
        
                       Under VMS, $^E provides the VMS status value from the last system error. This is more specific information about the last
                       system error than that provided by $!. This is particularly important when $!  is set to EVMSERR.
        
                       Under OS/2, $^E is set to the error code of the last call to OS/2 API either via CRT, or directly from perl.
        
                       Under Win32, $^E always returns the last error information reported by the Win32 call "GetLastError()" which describes the
                       last error from within the Win32 API. Most Win32-specific code will report errors via $^E. ANSI C and Unix-like calls set
                       "errno" and so most portable Perl code will report errors via $!.
        
                       Caveats mentioned in the description of $! generally apply to $^E, also.
        
                       This variable was added in Perl 5.003.
        
                       Mnemonic: Extra error explanation.
        
        

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

        I google it, but nothing useful.

        [ddg://"$^E" site:perl.org] -> "$^E" site:perl.org

        [google://"$^E" site:perl.org] -> "$^E" site:perl.org

        [google://"$^E" site:cpan.org] -> "$^E" site:cpan.org

        [perldoc://"$^E"] -> "$^E"

        Yeah, google seems to have gotten crappier, meh

        perldoc -v "$^E" $EXTENDED_OS_ERROR $^E Error information specific to the current operating system +. At ...

        $ perldoc perltoc |grep "\^E" , $COMPILING, $^C , $DEBUGGING, $^D , ${^ENCODING} , %ENV +, ${^CHILD_ERROR_NATIVE} , $EXTENDED_OS_ERROR, $^E , $^E is meaningful on Win32 $^E, $^H, $^M %ENV, CRTL_ENV, CLISYM_[LOCAL], Any other string, $!, $^E, $?, + $|

        [doc://perlvar#$^E] -> $^E

        You cant go wrong with a classic :) Tutorials: How to RTFM