summaryrefslogtreecommitdiff
path: root/prelude.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-29 12:48:43 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-29 12:48:43 +0000
commita828a658a421f750857e1e807d80d1a2a847c1c3 (patch)
tree9664a94a662594595beff5bfbdf70e9048f48a8a /prelude.rb
parentcd492563f8db2a6d81a498d21cd6d46853c81496 (diff)
* prelude.rb, .document: Stuff in prelude.rb should be documented
as well. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'prelude.rb')
-rw-r--r--prelude.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/prelude.rb b/prelude.rb
index 1d084dfd8f..40fca6ab36 100644
--- a/prelude.rb
+++ b/prelude.rb
@@ -1,7 +1,9 @@
-
-# Mutex
-
class Mutex
+ # call-seq:
+ # mutex.synchronize { ... }
+ #
+ # Obtains a lock, runs the block, and releases the lock when the
+ # block completes. See the example under Mutex.
def synchronize
self.lock
begin
@@ -12,10 +14,16 @@ class Mutex
end
end
-# Thread
-
class Thread
+ # :nodoc:
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
+
+ # call-seq:
+ # Thread.exclusive { block } => obj
+ #
+ # Wraps a block in Thread.critical, restoring the original value
+ # upon exit from the critical section, and returns the value of the
+ # block.
def self.exclusive
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
yield