Yes, you can create streams in front and make them wait for signals to appear and start their work.
These signals can be message queues or semaphores or any other way of exchanging between threads.
- UNIX, , . ( , ) .
, , slave- .
, ( pthreads). , , .
, "" , , ( ).
, " " - , .
, , , . , , , .
, . , , , ( ).
- :
master:
minslaves = 7
maxslaves = 20
maxtime = 600
numslaves = 0
freeslaves = 0
while running:
while numslaves < minslaves:
increment numslaves and freeslaves
start a slave
endwhile
wait for work
if freeslaves = 0 and numslaves < maxslaves:
start a slave
endif
queue work to slavequeue
endwhile
while numslaves > 0:
wait
endwhile
exit
slave:
while running:
get work from slavequeue with timeout
if timed out:
if time since last work > maxtime and numslaves > minslaves:
break out of while loop
endif
restart while loop
endif
decrement freeslaves
do the work
increment freeslaves
endwhile
decrement numslaves and freeslaves
exit
( , , numslaves, freeslaves, slavequeue , ).
, , - . - : -)