An alternative to forking is to run each make in its thread.
use threads; my $max_threads = 5; my @targets = qw(obj1.o obj2.o obj3.o ...); while(@targets) { my $num_threads = threads->list(threads::running); if( $num_threads < $max_threads ) { my $target = shift @targets; threads->create(sub { return system "make $target" }); } }
Unfortunately, I wave my hand around two bits. Firstly, making the loop wait until the stream ends. I believe this is achieved using threads :: shared cond_wait () and a semaphore variable.
The second is to get the return value from make, so you know that something failed, and stop the build. To do this, you will need to join () to each thread to get the result of system (), the process termination code.
Sorry for the hasty reply. We hope the community fills the rest.
source share