UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2010-04-14 10:13 AM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: order of flock acquiry?

hi all

given 4 processes which use flock() with exclusive lock in the following time order
p1: flock -> locked
p2: flock -> blocking
p3: flock -> blocking
p4: flock -> blocking

when p1 releases the lock
which process is the next to get the lock?
will it be p2 then p3 then p4 or is there a more complex rule in the kernel?
btw: maybe someone can point me to the kernel code for such lock's

thx

Offline

#2 2010-04-14 02:04 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,826
Website

Re: order of flock acquiry?

Look at "fs/locks.c" in your local kernel source...  It sounds like Linux tries to wake
the blocked lockers in the order they locked, though it's not required by any standard:

/* Insert waiter into blocker's block list.
 * We use a circular list so that processes can be easily woken up in
 * the order they blocked. The documentation doesn't require this but
 * it seems like the reasonable thing to do.
 */

Offline

Board footer

Powered by FluxBB