in reply to need a thread to wait until a buffer is full.
Something like this?
#! perl -slw use strict; use threads; use threads::shared; use Thread::Queue; $|++; sub filler { my( $Q ) = @_; while( my $ref = $Q->dequeue ) { lock $$ref; $$ref .= 'X'x10 while sleep 1 and length $$ref < 30; cond_signal $$ref; } } my $Q = new Thread::Queue; my $buffer :shared; my $filler = threads->create( \&filler, $Q ); for( 1 .. 5 ) { lock $buffer; $Q->enqueue( \$buffer ); cond_wait( $buffer ); print $buffer; $buffer = ''; } $Q->enqueue( undef ); ## kill thread $filler->join;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: need a thread to wait until a buffer is full.
by archfool (Monk) on Jul 25, 2007 at 02:42 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2007 at 05:32 UTC | |
by exodist (Monk) on Jul 25, 2007 at 07:12 UTC | |
by zentara (Cardinal) on Jul 25, 2007 at 12:17 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2007 at 12:45 UTC | |
|