In article <E075F54D-032F-4E9F-8FC8-7220FD8437FC / gmail.com>, ara howard <ara.t.howard / gmail.com> writes:
> On Feb 18, 2008, at 2:09 PM, Douglas Wells wrote:
> > In any case, right now Ruby seems to just use the OS's flock
> > function, and I don't think that it would be reasonable for the
> > Ruby implementation to attempt to get around this as it would be
> > far too messy -- and slow.  I'd just live with the problem.
> 
> http://codeforpeople.com/lib/ruby/posixlock/posixlock-0.0.1/README

Interesting -- and very confusing.  I (purposely) didn't look at
the source, but that documentation says that it's based on fcntl,
yet one interface is named lockf.  Unfortunately, in POSIX the
fcntl lock facility and lockf are distinct and behave differently.
So, if the module really has implemented lockf in terms of fcntl,
that's a big violation of the principle of least surprise.

> you really can't use flock on *nix systems anyhow, unless you are very  
> careful - flock is sometime implemented in terms of posixlock,  
> sometimes not.  when it is not the locks are incompatible and break on  
> many filesystems.

Can you elaborate on that, please?  Do you mean just in Ruby, or
in POSIX systems in general?  I don't understand the latter claim.
POSIX doesn't allow me to intermix the locking facilities in any
case, but the OS level flock ought to work as long as one only
uses flock in the other programs.  And, I've never even heard of
anything other than simple implementation bugs in 20+ years of
using it.

On the other hand, if you mean in Ruby, I'll note that the Ruby
documentation is quite sparse and uses many terms without defining
them (e.g., modification time, truncate, read permission) and often
explicitly refers to the OS platform documentation (e.g., "On Unix
systems, see chmod(2) for details."). So, I just assumed that
File#flock meant use the OS flock.  If I can't count on that, that
means that I can't count of interacting with non-Ruby programs via
the use of any kind of file locking.

The FreeBSD documentation says that all three locking forms interact
(i.e., taking a lock with one type would temporarily block a process
taking another).  At least one instance of Linux documentation,
however, notes that there is "no interaction between the types of
lock placed by flock(2) and fcntl(2)." I don't have time to test
this right now, but I read that as meaning that two separate
processes could concurrently each successfully take a lock on the
same file.  If I can't easily determine which locking method will
be used by Ruby, this situation would make this would make file
locking extremely dodgy and totally non-portable in Ruby.

> fyi

Thanks for the info, but now I'm extremely concerned about the
viability of any type of file locking in Ruby.  Can you tell me
which versions of Ruby don't use the OS platform flock in implementing
File#flock.

> a @ http://drawohara.com/

-- 
.   Douglas Wells             .  Connection Technologies      .
.   Internet:  -sp9804- -at - contek.com-                     .