Apache uses that model. It starts up a number of web server processes. When a request comes in, the main process forwards the request to one of the idle child processes*. It handles the request then waits to be asked to process another.
* I think this is optimized such that the implementation -- but not the effect -- differs from the above explanation.
| [reply] |
a trick would be to give each worker thread a shared "control" variable that is only used by that thread and the main thread. The main thread takes a lock on the variable, and the worker thread then tries to take a lock on it as well, which will block(put the thread to sleep) until the main thread uses cond_signal(part of threads::shared) to release the lock and hence wake up the worker thread. One might even configure said control variable to contain something useful, ie a filehandle that the worker thread needs to start working on.
| [reply] |
sub work{
my $dthread = shift;
$|++;
while(1){
if($shash{$dthread}{'die'} == 1){ goto END };
if ( $shash{$dthread}{'go'} == 1 ){
#in case I want to pass it code for evaling
eval( system( $shash{$dthread}{'data'} ) );
# a simple little task
foreach my $num (1..100){
$shash{$dthread}{'progress'} = $num;
print "\t" x $dthread,"$dthread->$num\n";
select(undef,undef,undef, .5);
if($shash{$dthread}{'go'} == 0){last}
if($shash{$dthread}{'die'} == 1){ goto END };
}
$shash{$dthread}{'go'} = 0; #turn off self before returning
}else
{ sleep 1 }
}
END:
}
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |