On Wednesday, June 23, 2004, at 05:25 PM, Ian Langworth wrote:
Hrm, I guess the confusion is in the "downgrading," as I believed that the parent was getting a new lock completely.
In some ways, you could treat it as giving up one lock and acquiring another. The only difference is that the process is atomic.
l1: open ONE, "<$file" or die; l2: open TWO, "<+$file" or die; l3: flock ONE, LOCK_SH or die; l4: flock TWO, LOCK_EX or die;
will not allow anyone else to grab the lock between the lines with the labels l3 and l4.
l3: flock ONE, LOCK_SH or die; l3_andahalf: flock ONE, LOCK_UN or die; l4: flock TWO, LOCK_EX or die;
might allow someone to sneak in and write between l3 and l4. Also note that no matter whether you are talking about the file handles ONE or TWO, you are talking about the same lock. A process has at most one lock on a file. The locks are referred to through the file handle, but are actually associated with the file it points to.
Also, because you didn't mention it, I just want to make sure that I got a point across from the previous post. The main problem with the code is that the child has no locks throughout its life span. If you want to test locking, you need two independent processes that each have active locks.
The book "Advanced Programming in the UNIX Environment" by W. Richard Stevens has a very good section on Unix file locking.
_______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm

