Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

flock on Linux

1 view
Skip to first unread message

rich coco

unread,
Jan 7, 2002, 12:04:01 PM1/7/02
to
Has anyone experienced difficulty using flock(2) on linux. In
particular, I am running RH 7.1.
The symptom is that using flock() with LOCK_SH (shared lock), threads
seem to be colliding when writing to the associated (presumably
flock-ed) file. that is, the lock is not honored and two threads can
overwrite each other. ouch!

anyone else seeing funny behavior wrt flock()?

or...any thoughts about how i might be mis-using it?

Tx

- rich

--
rac...@sockeye.com
Sockeye Networks
275 Grove St.
Newton, MA
617.559.4051

Peter Hanely

unread,
Jan 7, 2002, 9:09:15 AM1/7/02
to
rich coco wrote:

> Has anyone experienced difficulty using flock(2) on linux. In
> particular, I am running RH 7.1.
> The symptom is that using flock() with LOCK_SH (shared lock), threads
> seem to be colliding when writing to the associated (presumably
> flock-ed) file. that is, the lock is not honored and two threads can
> overwrite each other. ouch!
>
> anyone else seeing funny behavior wrt flock()?
>
> or...any thoughts about how i might be mis-using it?
>
> Tx
>
> - rich
>

flock() applies an *advisory* lock. Each thread would need to lock and
unlock the
filehandle at the begining and end of the critical section.
Alternately, a per process
lock could be used if a means, such as semiphores, keeps the threads out
of each
others way.


0 new messages