lock file so that it cannot be deleted

Posted by JoeCool on Stack Overflow See other posts from Stack Overflow or by JoeCool
Published on 2010-04-07T01:44:28Z Indexed on 2010/04/07 1:53 UTC
Read the original article Hit count: 313

Filed under:
|

I'm working with two independent c/c++ applications on Windows where one of them constantly updates an image on disk (from a webcam) and the other reads that image for processing. This works fine and dandy 99.99% of the time, but every once in a while the reader app is in the middle of reading the image when the writer deletes it to refresh it with a new one.

The obvious solution to me seems to be to have the reader put some sort of a lock on the file so that the writer can see that it can't delete it and thus spin-lock on it until it can delete and update. Is there anyway to do this? Or is there another simple design pattern I can use to get the same sort of constant image refreshing between two programs?

Thanks,

-Robert

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++