diff options
author | Burdette Lamar <[email protected]> | 2023-12-23 15:08:26 -0600 |
---|---|---|
committer | <[email protected]> | 2023-12-23 16:08:26 -0500 |
commit | 688a1314e60b0e58d5325f50c02552e3018c5025 () | |
tree | 5a7fa0d213cee12978b7fdddafae946e203f8b83 /file.c | |
parent | 47f33c38481d79563271f042946d0f3165d8b638 (diff) |
[DOC] Clean up doc for File#flock (#9332)
-rw-r--r-- | file.c | 102 |
1 files changed, 65 insertions, 37 deletions
@@ -5222,47 +5222,75 @@ rb_thread_flock(void *data) return (VALUE)ret; } -/* * call-seq: - * file.flock(locking_constant) -> 0 or false - * - * Locks or unlocks a file according to <i>locking_constant</i> (a - * logical <em>or</em> of the values in the table below). - * Returns <code>false</code> if File::LOCK_NB is specified and the - * operation would otherwise have blocked. Not available on all - * platforms. - * - * Locking constants (in class File): - * - * LOCK_EX | Exclusive lock. Only one process may hold an - * | exclusive lock for a given file at a time. - * ----------+------------------------------------------------ - * LOCK_NB | Don't block when locking. May be combined - * | with other lock options using logical or. - * ----------+------------------------------------------------ - * LOCK_SH | Shared lock. Multiple processes may each hold a - * | shared lock for a given file at the same time. - * ----------+------------------------------------------------ - * LOCK_UN | Unlock. * * Example: * - * # update a counter using write lock - * # don't use "w" because it truncates the file before lock. - * File.open("counter", File::RDWR|File::CREAT, 0644) {|f| - * f.flock(File::LOCK_EX) - * value = f.read.to_i + 1 - * f.rewind - * f.write("#{value}\n") - * f.flush - * f.truncate(f.pos) - * } - * - * # read the counter using read lock - * File.open("counter", "r") {|f| - * f.flock(File::LOCK_SH) - * p f.read - * } * */ |