How to Lock a file and avoid readings while it's writing
My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return the file while other thread is creating it. Also, I don't want to get a lock over a element that is common for all the files. Therefore I should lock the file just when I'm creating it. So I want to lock a file till its recreation is complete, if other thread