I have to maintain a data file data.cur which has to be rolled to a new file data. periodically. So I am renaming the file periodically, and write to new file when timeout. Renaming and writing to a file are done in different threads. When these are done concurrently, how to synchronize them?