1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Thread.exclusive: delete

Has been deprecated since 2069c9e031.

[Feature #17125][ruby-core:99636]
This commit is contained in:
卜部昌平 2020-07-28 10:58:37 +09:00 committed by Kazuhiro NISHIYAMA
parent eb9342d348
commit b674fc9ca2
No known key found for this signature in database
GPG key ID: 262ED8DBB4222F7A
2 changed files with 34 additions and 47 deletions

View file

@ -1,18 +1,3 @@
class << Thread
# call-seq:
# Thread.exclusive { block } -> obj
#
# Wraps the block in a single, VM-global Mutex.synchronize, returning the
# value of the block. A thread executing inside the exclusive section will
# only block other threads which also use the Thread.exclusive mechanism.
def exclusive(&block) end if false
mutex = Mutex.new # :nodoc:
define_method(:exclusive) do |&block|
warn "Thread.exclusive is deprecated, use Thread::Mutex", uplevel: 1
mutex.synchronize(&block)
end
end
class Binding class Binding
# :nodoc: # :nodoc:
def irb def irb

View file

@ -1,47 +1,49 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
describe "Thread.exclusive" do ruby_version_is ''...'2.8' do
before :each do describe "Thread.exclusive" do
ScratchPad.clear before :each do
$VERBOSE, @verbose = nil, $VERBOSE ScratchPad.clear
end $VERBOSE, @verbose = nil, $VERBOSE
end
after :each do after :each do
$VERBOSE = @verbose $VERBOSE = @verbose
end end
it "yields to the block" do it "yields to the block" do
Thread.exclusive { ScratchPad.record true } Thread.exclusive { ScratchPad.record true }
ScratchPad.recorded.should == true ScratchPad.recorded.should == true
end end
it "returns the result of yielding" do it "returns the result of yielding" do
Thread.exclusive { :result }.should == :result Thread.exclusive { :result }.should == :result
end end
it "blocks the caller if another thread is also in an exclusive block" do it "blocks the caller if another thread is also in an exclusive block" do
m = Mutex.new m = Mutex.new
q1 = Queue.new q1 = Queue.new
q2 = Queue.new q2 = Queue.new
t = Thread.new { t = Thread.new {
Thread.exclusive { Thread.exclusive {
q1.push :ready q1.push :ready
q2.pop q2.pop
}
} }
}
q1.pop.should == :ready q1.pop.should == :ready
-> { Thread.exclusive { } }.should block_caller -> { Thread.exclusive { } }.should block_caller
q2.push :done q2.push :done
t.join t.join
end end
it "is not recursive" do it "is not recursive" do
Thread.exclusive do Thread.exclusive do
-> { Thread.exclusive { } }.should raise_error(ThreadError) -> { Thread.exclusive { } }.should raise_error(ThreadError)
end
end end
end end
end end