Think about Loose Coupling | |
PerlMonks |
Re: thread save calling an external commandby oiskuu (Hermit) |
on Jun 15, 2016 at 17:34 UTC ( [id://1165759]=note: print w/replies, xml ) | Need Help?? |
I don't think run3 can be used in a threaded environment. Looking at the module code, it makes the redirects, then does system() i.e. fork/exec. A thread-safe version would open the streams; fork(); redirect i/o; exec(). The second problem is waiting upon the processes. You'll need a mechanism to catch child notifications and forward them to the interested threads (via Thread::Queue probably). In the end, it might be smarter to implement a separate job-controller thread to launch and reap the external jobs. Update. On a second thought, if your workers only ever wait on a single process at a time, you can get away with just the waitpid($pid, 0); and no job control is necessary...
In Section
Seekers of Perl Wisdom
|
|