|Do you know where your variables are?|
Interprocess pipe doesn't reliably deliver databy fhew (Beadle)
|on Mar 16, 2006 at 17:33 UTC||Need Help??|
fhew has asked for the wisdom of the Perl Monks concerning the following question:
I have a simple program that forks a child, and uses a pipe between them to deliver messages to the child. I use select on the child to determine when data arrives to process, while it also goes off to do other things.
What I'm seeing is that the child (at random) stops getting the indication (in a 'select') that there is data to read, so once it gets into this 'mode', I never see any more data from the parent even though its there (as proven when I blindly do a read some time in the future.)
I've narrowed down my problem to the shortest test code I can, but due to timing issues, it may or may not fail the same on your machine. If you remove the 'time-waster', it works, but the more stuff you do in the child (it doesn't matter what), the worse it gets.
Or is the problem when 'there was more than one write to the pipe before the other end reads it'? If so... a) thats silly, and b) how would you get around it?
Here is a (annotated) sample run that fails: (Note that messages 4, 5, 6, 7, 8 never got picked up via the select, but later when I just read STDIN explicitly, the data _is_ there.)
Here is the test code. Can anyone tell me what I'm doing wrong?