ruby-changes:11017
From: akr <ko1@a...>
Date: Wed, 25 Feb 2009 02:19:00 +0900 (JST)
Subject: [ruby-changes:11017] Ruby:r22607 (trunk): rdoc update.
akr 2009-02-25 02:18:55 +0900 (Wed, 25 Feb 2009) New Revision: 22607 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22607 Log: rdoc update. Modified files: trunk/file.c Index: file.c =================================================================== --- file.c (revision 22606) +++ file.c (revision 22607) @@ -3499,15 +3499,18 @@ * * Example: * - * # write lock + * # update a counter using write lock * # don't use "w" because it truncates the file before lock. - * File.open("testfile", File::WRONLY|File::CREAT, 0644) {|f| + * File.open("counter", File::RDWR|File::CREAT, 0644) {|f| * f.flock(File::LOCK_EX) - * f.truncate(0) - * f.write "new content" + * value = f.read.to_i + 1 + * f.rewind + * f.write("#{value}\n") + * f.flush + * f.truncate(f.pos) * } * - * # read lock + * # read the counter using read lock * File.open("testfile", "r") {|f| * f.flock(File::LOCK_SH) * p f.read -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/