File#flock incompatibilities
----------------------------
Key: JRUBY-4386
URL: http://jira.codehaus.org/browse/JRUBY-4386
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules, RubySpec
Affects Versions: JRuby 1.4
Environment: jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2009-12-24
aacb504) (Java HotSpot(TM) Client VM 1.6.0_17) [x86-java]
Reporter: Vladimir Sizikov
Java's java.nio.channels.FileLock behaves in such a way that "The locks held on
a particular file by a single Java virtual machine do not overlap.". That means
that it is impossible to lock the same file (even in shared mode) from within
the same JVM:
{code}
f = File.open('xxx', 'w+')
f2 = File.open('xxx', 'w+')
p f.flock(File::LOCK_SH)
p f2.flock(File::LOCK_SH)
{code}
This prints 0, 0 on MRI, and 0, false on JRuby (second flock does not succeed).
While the native C call does allow this, Java explicitly has additional checks
to disallow such behavior.
This also caused one new rubyspec failure:
{code}
mspec -t j core\file\flock_spec.rb
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2009-12-24 aacb504) (Java
HotSpot(TM) Client VM 1.6.0_17) [x86-java]
...F
1)
File#flock returns 0 if trying to lock a non-exclusively locked file FAILED
Expected false
to equal 0
D:/work/jruby-dev/rubyspec.git/core/file/flock_spec.rb:39
D:/work/jruby-dev/rubyspec.git/core/file/flock_spec.rb:38:in `open'
D:/work/jruby-dev/rubyspec.git/core/file/flock_spec.rb:38
D:/work/jruby-dev/rubyspec.git/core/file/flock_spec.rb:3
D:/work/jruby-dev/rubyspec.git/core/file/flock_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8
Finished in 0.064000 seconds
{code}
P.S. Interesting discussion, which might have some relevance to this issue:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24412
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email