F_SETLK/F_SETLKW unsuitable for multithreaded programs ?



Hi folks!

Is fcntl(F_SETLK/F_SETLKW) supposed to be suitable for multithreaded applications ?

As nicely explained by Nelson Bolyard, many implementations (confirmed on Linux and Solaris 10 for example) are prone to false deadlock detection (https://bugzilla.mozilla.org/show_bug.cgi?id=62457)

To summarize the issue, if two programs are working on two separate files in their "main" thread, and then have an additional thread attempting to lock the peer's file (hence, having the two secondary threads blocked in both process until the primary threads have finished), the locking functions will return a spurious EDEADLK errno.

It is unclear whether this behavior is an implementation bug^Wchoice or a standard glitch.
http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.html

Note that alternate solutions are not very useful either:
* flock() is thread-unsafe (and even unavailable on Solaris)
* lockf() has no "shared" mode
.



Relevant Pages

  • Re: inserting 2 tab chars/spaces between field 1 and field2
    ... behave differently on different implementations. ... But on Linux: ... - The OP said something about Solaris. ... Gnu versions of utilities are available.) ...
    (comp.unix.shell)
  • Re: HEADS UP: pts code committed
    ... >Well, strictly speaking, those are just symlinks into /devices, but it comes ... You are probably right, though -- naming them ... I had a quick look on a Solaris 8 machine and found only legacy pty devices ... the other implementations seem to get by without putting ...
    (freebsd-current)
  • SUMMARY: Port Knocking Daemons for Solaris?
    ... which has a useful overview of the idea plus a list of implementations. ... > Can anybody recommend a port knocking daemon for Solaris? ...
    (SunManagers)
  • Re: Support for COM on Solaris
    ... > Does Solaris support COM/DCOM architecture?? ... I think there's at least a couple of implementations, ... know of a fully free one. ...
    (comp.unix.solaris)
  • Re: Setting Time on Mail Servers
    ... Bill Cole wrote: ... Am using Solaris 9 as an OS, date is the normal date command on solaris ... Note that the man page for TIMEZONE refers you to the man page for environ ... Some implementations of 'date' will look for $TZ in your environment, ...
    (comp.mail.sendmail)