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;
In reply to Re: need a thread to wait until a buffer is full.
by BrowserUk
in thread need a thread to wait until a buffer is full.
by exodist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |