Re: Behavior of flock() oriented procedures



On Jun 2, 6:55 am, arcf...@xxxxxxxxxxx (Aaron Hsu) wrote:
Jens Thoms Toerring <j...@xxxxxxxxxxx> wrote:

I am trying to add an additional feature to Scheme's normal procedures
of OPEN-INPUT-FILE and family of CALL-WITH and WITH- procedures which
deal with files. The input/output datatype in Scheme is a port, but
unfortunately, a port does not explicitly have a unique file descriptor
available to implementations. I could use a file descriptor to make a
generic port on some Scheme implementations, but this isn't very nice
because it bypasses the native file ports support on implementations
that have faster file ports.

If indeed I need to save the file descriptor to use it later, then I
think I have no choice but to return a file lock object which later is
used to "unlock" the object. This will unfortunately create two
connections to the file, and make for some nasty interactions if we are
cose to the maximum limit of opened files. I have run into this before,
so I know it can be a problem.

The types of locking I have used are:

fcntl, lockf - no good because the lock is lost when you close *any*
descriptor for the file.

flock - the lock is lost when you close *all* descriptors dup()ed from
the one you obtained it for.

dotlock (to lock /file create /file.lock) - persistent but slow -
also if your program gets killed the lock remains forever, also, some
programs ignore dotlocks that they *guess* are stale.

cclient - (similar to dotlock, but create /tmp/.dev#.ino# and then
flock it) - more or less like dotlock but used where you might not
have write permission in the directories where you want to lock files.

So if you want persistent locking you need to use a file system based
one like dotlock - but these don't work if O_EXCL doesn't work, and
are slower.

If you are only trying to lock files so that other copies of your own
program don't mess with them, then it might be best to implement your
own locking method.

Regarding your point about too many open files, does it help if your
"lock object" is a dup()ed descriptor rather than an open()ed one?

viza
.



Relevant Pages

  • Re: Handling locked db tables...
    ... When choosing a port the table is read and the first available ... When I run a "lock table mytable read" I can do all of my ... This is normal database locking behavior. ... using an indicator that's unique to the process/thread requesting the ...
    (comp.lang.python)
  • Re: libc_r is deprecated
    ... > libpthread, if I use ULE, libpthread is far behind than libthr, I ... - Experiment with reducing contention on the file descriptor lock through ... contention on the lock really is the cause. ...
    (freebsd-arch)
  • filedesc_sx patch (20070401a)
    ... The attached patch moves file descriptor locks from being a custom mutex/sleep lock implemented using msleepto an sx lock. ... Kris has reported 2x-4x improvement in transactions/sec with MySQL using this patch, as it greatly reduces the cost of lock contention during file descriptor lookup for threaded applications, and also moves to shared locking to avoid exclusive acquisition for read-only operations. ... struct vnode *dvp; ... fdunused(struct filedesc *fdp, int fd) ...
    (freebsd-current)
  • filedesc_sx patch (20070401a)
    ... The attached patch moves file descriptor locks from being a custom mutex/sleep lock implemented using msleepto an sx lock. ... Kris has reported 2x-4x improvement in transactions/sec with MySQL using this patch, as it greatly reduces the cost of lock contention during file descriptor lookup for threaded applications, and also moves to shared locking to avoid exclusive acquisition for read-only operations. ... struct vnode *dvp; ... fdunused(struct filedesc *fdp, int fd) ...
    (freebsd-performance)
  • Re: [lm-sensors] Could the k8temp driver be interfering with ACPI?
    ... You'll need to take some lock, and if you want port emulation ... By callback, do you mean port forwarding as Rudolf Marek did, or more ... Some drivers will not understand all possible access patterns, ... What benefit do you see compared to a lock taken by both AML and the ...
    (Linux-Kernel)