David wrote:
I have an email from David referring to man IPC::Open2 on the dangers of open2. But I can't say I really understand why this deadlock occurs or how it can be avoided.
The problem is that when you do fprintf(), there is no guarantee that the data has actually been written out of the process buffers. So process A thinks it has sent the command and is blocked waiting for the reply. But the message is still in A's stdio buffers, and so process is still blocked waiting to read it. => deadlock.
But in this case the printf is done by the perl twogtp command:
print $black_in "boardsize $size\n";
Here $black_in is the file descriptor created with:
$pidb = open2($black_out, $black_in, $black);
and man IPC::Open2 says:
The write filehandle will have autoflush turned on.
Doesn't this mean that the data should have been written out of the buffer?
Dan