in reply to Re^2: avoiding a race (does lock, still racy)
in thread avoiding a race
That is not a non-locking mechanism. It just hands off the locking to the kernel which locks the directory when it reads from it or writes to it. It has the advantage of the kernel locking implementation being very well tested.
The kernel is going to do it's locking whatever file operations you do. Re-using it is good.
So, I guess you could call it a "no-extra, no-effort(or risk of getting it wrong)" locking mechanism.
Of course, errors might not all have such nice, unique, numeric identifiers ...
If you can't reduce the errors to something easily comparible in the filesystem, you'll have similar problems locating similar errors in the file itself. And globbing is capable of much more that just "string equality".
But, most importantly, your solution (as described) has a race condition between stat and creating a file. You can probably fix that a couple of different ways.
If I knew how to do open(CREATE_NEW(*)) in Perl, I would suggest that. If the open() fails, it must have 'just' been created, so there's nothing else to do, so you just move on anyway.
But realistically, it's probably a "problem" not worth the effort of solving. The idea is to avoid 300 emails. Getting 2 or even 3 shouldn't be a problem.
Update: The "race condition", whether this process creates a new file; or some other process does it for you a few milliseconds before you do, doesn't trigger extra emails.
Nor does it delay their being sent at the appropriate time. the time window is probably less than the resolution of the file system timestamps. So. NO race condition!
Very simple. Very effective. Perfection is the enemy of "good enough".
(*)Ie. Create a new file; fail if it already exists.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: avoiding a race ("No extra", "no-user" locking--miniscule race of no importance)
by Kanji (Parson) on Sep 28, 2010 at 20:17 UTC | |
Re^4: avoiding a race (much ado)
by tye (Sage) on Sep 29, 2010 at 19:05 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 19:56 UTC | |
by tye (Sage) on Sep 29, 2010 at 20:53 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 21:17 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 21:10 UTC | |
by tye (Sage) on Sep 29, 2010 at 21:41 UTC | |
|