in reply to Re: Mysterious Disapperance of file contents
in thread Mysterious Disapperance of file contents

That was my first thought, (hence my award-winning post above), but after reading the doc on flock, it appears that purpose of the flock isn't to stop the second program from opening the file - instead it stops the second program from obtaining the lock - the second program's flock(HANDLE, LOCK_EX) blocks until the first program issues flock(HANDLE, LOCK_UN).

The doc on flock shows a sequence much like that used by the OP, but without use of a spearate seamphore file.

Testing things very similar to the OP's code seems to work as expected. I don't see the issue.

--Bob Niederman, http://bob-n.com

All code given here is UNTESTED unless otherwise stated.

  • Comment on Re: Re: Mysterious Disapperance of file contents