summaryrefslogtreecommitdiff
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
commit6c6a24826c5fda68e04e71ac17620b0e70bca265 (patch)
treec2692457fbae375c8a38fd64a90a852365e331fc /lib/thread.rb
parent1a760a6f76e5b2fad343fce10ebf831fe22286b4 (diff)
* enum.c (enum_min_by): new method Enum#min_by. added Enum#max_by
as well. git-svn-id: svn+ssh://ci.ruby-lang.org/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 8b27356c48..a069c4680a 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