runtime/syncproc: Eliminate spinning, and blocking.
The run-shell-command spins when it is copying both stdin and stdout.
E.g.
(call-with-input-string "Lorem ipsum dolor sit amet\n"
(lambda (in)
(run-shell-command "sleep 10; cat" 'input in)))
will keep your machine busy for 10 seconds.
When it is not spinning, the procedure blocks for large bufferfuls.
During the evaluation of
(run-shell-command
"i=0; while [ $i -lt 5 ]; do echo $i; i=$[$i + 1]; sleep 1; done"
'redisplay-hook flush-output-port)
you will not see 5 lines of output, one each second, but all 5 lines
at once after 5 seconds, despite the redisplay hook [Linux 4.10.0
glibc 2.24].
This new copying process eliminates the blocking AND the spinning. It
keeps stdout in nonblocking mode and uses suspend-current-thread to
block. It handles short writes too. The ports sourcing/sinking
stdin/stdout are required to block.