From ec3c6d647c3eed056dff01d7493dd74ea7a56299 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 24 Feb 2009 17:18:55 +0000 Subject: rdoc update. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 7b4303acd..0e3a2d209 100644 --- a/file.c +++ b/file.c @@ -3499,15 +3499,18 @@ rb_thread_flock(void *data) * * 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 -- cgit