summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-24 17:18:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-24 17:18:55 +0000
commit01e9a7be61ad5a9be0fe3a0c6c469d03ff21f51e (patch)
tree1cc6288bcc9fc4059d78dd08f870917526a68053 /file.c
parent42eeb2c1b1788c5975d2a383c9b0c3ff2c90b6b8 (diff)
rdoc update.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/file.c b/file.c
index 7b4303acd9..0e3a2d209f 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