in reply to Data Between Threads
Simple example to get you started:
The main thread is your thread C.#! perl -slw use strict; use threads; use Thread::Queue; sub threadA { my $Qab = shift; for( 1 .. 1e6 ) { $Qab->enqueue( 1+int rand 1000 ); } $Qab->enqueue( undef ); } sub threadB { my( $Qab, $Qbc ) = @_; while( my $in = $Qab->dequeue() ) { $Qbc->enqueue( $in * 10 ); } $Qbc->enqueue( undef ); } my $Qab = new Thread::Queue; my $Qbc = new Thread::Queue; threads->new( \&threadA, $Qab )->detach; threads->new( \&threadB, $Qab, $Qbc )->detach; print while defined( $_ = $Qbc->dequeue ); print 'Done';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Data Between Threads
by UpTide (Novice) on Aug 17, 2016 at 16:09 UTC | |
by BrowserUk (Patriarch) on Aug 17, 2016 at 16:16 UTC | |
by GotToBTru (Prior) on Aug 17, 2016 at 16:28 UTC |