Mj1234 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am trying to debug an exe using GDB debugger and using perl thread for it. I have attached a thread to the gdbserver and the exe is attached to the gdbserver as shown.

$self_ph->{GDBSERVERTHREAD} = threads::async{ $gdbserver_path :6000 $Exe_path 1> NUL 2> NUL` ; threads->exit(); }; $self_ph->{IN_QUEUE} = new Thread::Queue;

Everything works fine but in my kill module the exe does not terminate and the join function is executed the control does not return. Is there something that I am missing?

`taskkill /F /IM My_Exe.exe`; $self_ph->{GDBSERVERTHREAD}->join(); $self_ph->{GDBSERVERTHREAD} = undef;

Replies are listed 'Best First'.
Re: join() in perl threads does not return
by Corion (Patriarch) on Oct 01, 2016 at 08:43 UTC

    If you are on Windows and want to launch a process in the background, maybe consider avoiding threads and use the special form of system, as documented in perlport:

    my $child_pid = system(1, @args); ... kill 9 => $child_pid; # boom
Re: join() in perl threads does not return
by BrowserUk (Patriarch) on Oct 01, 2016 at 10:39 UTC

    Don't do the threads->exit, just fall off the end.

    But corion is correct. If you are just after an asynchronous process, $pid = system( 1, ... ) or Win32::Spawn( ... ) is the way to go.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I tried without thread->kill() but still the joining of threads just freezes without returning.

        Hm. In that case you'll need to post actual code, that is runnable and demonstrates the problem.

        • Actual code:

          Ie. This code: $gdbserver_path :6000 $Exe_path 1> NUL 2> NUL` ; from your OP, is not valid Perl.

          1. There is an unmatched backtick (`) at the end of the line, but none at the start.
          2. Whilst not illegal, a command line parameter that starts ':' is unusual.
          3. You are redirecting both stdout and stderr to nul, then what is the point of backticks? (They are designed to return the output of the spawned program to the spawner.)
          4. Ditto: Why use backticks (rather than system) if you aren't going to assign the output to a variable and use it?
        • Runnable: means that we will have a good chance of running the code you post.

          Ie. It mustn't have dependencies that we cannot have access to -- like modules that are your companies intellectual property.

          We don't need to have the executable you are running, we can mock that up using a perl 1-liner.

        • demonstrates the problem: hopefully, self explanatory.

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.