summaryrefslogtreecommitdiffstats
path: root/lib/thread.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-14 14:51:42 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-14 14:51:42 +0000
commit0811bd70e416daa03924286c8f324d76faad2a09 (patch)
treec2692457fbae375c8a38fd64a90a852365e331fc /lib/thread.rb
parenteced484a5617c21b6723078947ee1fd7b1475fa1 (diff)
downloadruby-0811bd70e416daa03924286c8f324d76faad2a09.tar.gz
ruby-0811bd70e416daa03924286c8f324d76faad2a09.tar.xz
ruby-0811bd70e416daa03924286c8f324d76faad2a09.zip
* enum.c (enum_min_by): new method Enum#min_by. added Enum#max_by
as well. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/thread.rb')
-rw-r--r--lib/thread.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/thread.rb b/lib/thread.rb
index 8b27356c4..a069c4680 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -69,7 +69,7 @@ class Mutex
# Returns +true+ if this lock is currently held by some thread.
#
def locked?
- @locked
+ @locked && true
end
#
@@ -80,7 +80,7 @@ class Mutex
result = false
Thread.critical = true
unless @locked
- @locked = true
+ @locked = Thread.current
result = true
end
Thread.critical = false
@@ -92,10 +92,13 @@ class Mutex
#
def lock
while (Thread.critical = true; @locked)
+ if @locked == Thread.current
+ raise ThreadError, "deadlock; recursive locking"
+ end
@waiting.push Thread.current
Thread.stop
end
- @locked = true
+ @locked = Thread.current
Thread.critical = false
self
end