in reply to Perl thread issue

I have figured out issue since every data element we pass to thread is copied down so queue enqueue and dequeue are not working on same queue due to which second program is not working. But i am not sure how to solve this problem ?

Replies are listed 'Best First'.
Re^2: Perl thread issue
by Anonymous Monk on Dec 29, 2016 at 00:14 UTC

    I have figured out issue since every data element we pass to thread is copied down so queue enqueue and dequeue are not working on same queue due to which second program is not working. But i am not sure how to solve this problem ?

    How did you figure that out?

    See https://metacpan.org/pod/Thread::Queue#end

    Use a different way to signal the end, like

    $q->enqueue( [ 'capture' => 'ls -la' ] ); ... $q->enqueue( [ 'exit' ] ); ... while ((my $jackson = $q->dequeue())) my( $action, @args ) = @$jackson; last if $action eq 'exit'; if( $action eq 'capture' ){ my $result ... @args ...
      read perl thread documentation here : http://perldoc.perl.org/perlthrtut.html Section shared and unshared data. It mentions below The biggest difference between Perl ithreads and the old 5.005 style threading, or for that matter, to most other threading systems out there, is that by default, no data is shared. When a new Perl thread is created, all the data associated with the current thread is copied to the new thread, and is subsequently private to that new thread! This is similar in feel to what happens when a Unix process forks, except that in this case, the data is just copied to a different part of memory within the same process rather than a real fork taking place.