Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: avoiding a race (read locks)

by westy032001 (Novice)
on Sep 28, 2010 at 15:31 UTC ( #862450=note: print w/replies, xml ) Need Help??

in reply to Re: avoiding a race (read locks)
in thread avoiding a race

Thanks for the reply.

If I understand you correctly, isnt there still a potential for a race condition ?

If the database goes down and all 300 procs get a db error.

process 123 open file and places a shared lock

process 321 opens file and places a shared lock

process 123 decides it is going to modify the file and so waits for 123 to unlock then places an exclusive lock modifies file and closes

process 321 decides it is going to modify the file and so places an exclusive lock modifies file and closes.

If both are changing the file as a result of the same error (i.e database is down) you will get 2 of the same error codes recorded. and 2 emails sent to admins .


Replies are listed 'Best First'.
Re^3: avoiding a race (read locks)
by Corion (Pope) on Sep 28, 2010 at 15:48 UTC

    See the following sentence in tye's scheme:

    When you get [the write lock], you read from the position in the file that was the previous end of the file and update your decision as to whether you need to write.

    So, in your example case, Process 321 would notice that the file changed since it last checked and that another process already sent the notification.

      Thanks, Corion.

      I also should have pointed out that, in order to keep reading past what had previously been the end-of-file, you'll need to seek( $fh, 0, 0 ) (if you don't just re-open the file).

      - tye        

      aha ! Thank you !

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862450]
[Corion]: ambrus: AnyEvent(::HTTP) doesn't integrate well with Prima, that's my main problem
[Corion]: There is a weirdo shim because there is a POE integration for Prima, and if you use that, you can use the POE adapter of AnyEvent. What I'd want is something transport agnostic that parses HTTP or produces HTTP output, so that the communication with ...
[Corion]: ... the socket is done by my code. Ideally that module would not be based on callbacks ;)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2016-12-07 15:45 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (130 votes). Check out past polls.