in reply to Boolean Thread::Semaphore ?
Is there a way of using Thread::Semaphore in this way, or an alternative semaphore module that can be used for this purpose?
You don't want a semaphore.
The simplest mechanism is:
wbile( my $workitem = sourceOfWork() ) { sleep 1 while $Q->pending > MAXQ; $Q->enqueue( $workitem ); }
If you are concerned that the queue might empty during that 1 second, use Time::HiRes::usleep().
If you really insist on not polling the queuesize, then use a condition vatiable:
my $cond :shared; ... wbile( my $workitem = sourceOfWork() ) { cond_wait( $cond ); $Q->enqueue( $workitem ); } ## somewhere else ... ... cond_signal( $cond ) if $Q->pending < MAXQ; ...
But really, the latter involves more work and is less effective.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Boolean Thread::Semaphore ?
by chrestomanci (Priest) on Feb 08, 2012 at 16:10 UTC | |
by mellon85 (Monk) on Feb 08, 2012 at 17:28 UTC | |
by BrowserUk (Patriarch) on Feb 08, 2012 at 19:00 UTC |