Re: threads and file locking doesn't work correct

Bill Hawes (
Tue, 24 Feb 1998 09:34:31 -0500 wrote:

> I have a big problem with file locking and threads under Linux.
> Before I start threads, I create a pid file which will be locked with fcntl.
> After killing the program (killall or Ctrl-C), the lock will not be
> removed always. When starting the program again, I get the error message,
> that pid <xxx> owns the lock, but there is no program running with this pid.

You didn't mention which kernel you're using, but people are aware of the
problems with locking and threads. 2.1.88 includes a patch to split the lock
removal code into two parts as a first step in addressing the problem.
POSIX-style locks need a further change to consider the lock as associated with
an fd-array rather than a pid, as all clone tasks (threads) will share one fd
array. Flock-style locks should be removed correctly when the last close of the
file structure occurs.

I've also just posted a patch to test for remaining locks on unused inodes to
make sure this isn't occurring.

> Any chance to fix this ? I need threads and file locking.

Yes, excellent chances of getting it fixed -- this is Linux.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to