in reply to Re: Unique filenames with Time::HiRes
in thread Unique filenames with Time::HiRes

you could just add an additional integer to your filename, so it will be unique. if you start with 0 and go up, you even have the real order.

generate the filename, test if a file allready exists with this if not create one... you don't need locking for that.

Actually, you would need locking for that, unless you have an atomic test-and-create-file function. Otherwise, you could have two processes which end up in a race condition:
Process 1 checks for filename XXX-42, doesn't exist Process 2 checks for filename XXX-42, doesn't exist Process 1 creates filename XXX-42 and starts writing to it Process 2 opens filename XXX-42 and starts writing to it Process 1 finishes writing to XXX-42 Process 2 finishes writing to XXX-42
Then what's in the file? Who knows? Probably not what you want.

Replies are listed 'Best First'.
Re^3: Unique filenames with Time::HiRes
by knoebi (Friar) on Jul 19, 2004 at 15:03 UTC
    You are correct about this. You have to look that File XX-42, but the other process don't have to wait until the process which has opened XX-42 finishs. This was part of his question.