On 6/11/07, oryann9 <[EMAIL PROTECTED]> wrote:
snip
If you use LOCK_NB and are refused a LOCK_SH, then you
know that someone else has a LOCK_EX and is updating
the file. If you are refused a LOCK_EX, then someone
holds either a LOCK_SH or a LOCK_EX, so you shouldn't
try to update the file.
snip

I am not sure what you are asking, but I assume you don't understand
what the flock flags are for.  The flock function normally waits until
a lock can be achieved.  This could be forever (especially in the case
of a deadlock*), so it provides a flag LOCK_NB that lets you tell it
to run in Non-Blocking (NB) mode.  It will return immediately with
either true (if the requested lock type was made) or false (it
couldn't lock the file).  The two types of lock are shared (SH) and
exclusive (EX).  A given file can have an unlimited number of shared
locks at the same time, but if a file has been exclusively locked then
no other process can lock it (with either a shared or an exclusive
lock).  Think of shared locks as saying "I am reading this file don't
change it."  Many different processes can all read the same file
without causing a problem (so long as no one changes it).  Think of
exclusive locks as saying "I am going to change this file."  Only one
process at a time can safely change a file.

Hope that helps.


* A simple deadlock can be achieved like this
1. process A locks file foo
2. process B locks file bar
3. process A tries to lock file bar
4. process B tries to lock file foo
Both processes will wait forever for the other process to let go of
the others lock.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to