git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-08-30 06:22:30 +00:00
Родитель 0df79477bd
Коммит 4b298ad77a
50 изменённых файлов: 100 добавлений и 93 удалений

Просмотреть файл

@ -1,6 +1,6 @@
require 'thread'
m = Mutex.new
m = Thread::Mutex.new
i = 0
while i<6_000_000 # benchmark loop 2

Просмотреть файл

@ -1,7 +1,7 @@
# one thread, one mutex (no contention)
require 'thread'
m = Mutex.new
m = Thread::Mutex.new
r = 0
max = 2000
lmax = max * max

Просмотреть файл

@ -1,7 +1,7 @@
# two threads, one mutex
require 'thread'
m = Mutex.new
m = Thread::Mutex.new
r = 0
max = 2000
lmax = (max * max)/2

Просмотреть файл

@ -1,7 +1,7 @@
# 1000 threads, one mutex
require 'thread'
m = Mutex.new
m = Thread::Mutex.new
r = 0
max = 2000
(1..max).map{

Просмотреть файл

@ -1,7 +1,7 @@
require 'thread'
n = 1_000_000
q = Queue.new
q = Thread::Queue.new
consumer = Thread.new{
while q.pop
# consuming

Просмотреть файл

@ -35,7 +35,7 @@ assert_normal_exit %q{
assert_normal_exit %q{
ObjectSpace.define_finalizer("") do
Mutex.new.lock
Thread::Mutex.new.lock
end
}, '[ruby-dev:44049]'

Просмотреть файл

@ -347,7 +347,7 @@ assert_equal 'ok', %q{
assert_equal 'ok', %q{
begin
m1, m2 = Mutex.new, Mutex.new
m1, m2 = Thread::Mutex.new, Thread::Mutex.new
f1 = f2 = false
Thread.new { m1.lock; f2 = true; sleep 0.001 until f1; m2.lock }
m2.lock; f1 = true; sleep 0.001 until f2; m1.lock
@ -358,32 +358,32 @@ assert_equal 'ok', %q{
}
assert_equal 'ok', %q{
m = Mutex.new
m = Thread::Mutex.new
Thread.new { m.lock }; sleep 0.1; m.lock
:ok
}
assert_equal 'ok', %q{
m = Mutex.new
m = Thread::Mutex.new
Thread.new { m.lock }; m.lock
:ok
}
assert_equal 'ok', %q{
m = Mutex.new
m = Thread::Mutex.new
Thread.new { m.lock }.join; m.lock
:ok
}
assert_equal 'ok', %q{
m = Mutex.new
m = Thread::Mutex.new
Thread.new { m.lock; sleep 0.2 }
sleep 0.1; m.lock
:ok
}
assert_equal 'ok', %q{
m = Mutex.new
m = Thread::Mutex.new
Thread.new { m.lock; sleep 0.2; m.unlock }
sleep 0.1; m.lock
:ok
@ -409,7 +409,7 @@ assert_equal 'ok', %{
open("zzz.rb", "w") do |f|
f.puts <<-'end;' # do
begin
m = Mutex.new
m = Thread::Mutex.new
parent = Thread.current
th1 = Thread.new { m.lock; sleep }
sleep 0.01 until th1.stop?
@ -437,8 +437,8 @@ assert_equal 'ok', %{
assert_finish 3, %q{
require 'thread'
lock = Mutex.new
cond = ConditionVariable.new
lock = Thread::Mutex.new
cond = Thread::ConditionVariable.new
t = Thread.new do
lock.synchronize do
cond.wait(lock)

Просмотреть файл

@ -3,7 +3,7 @@ require 'digest.so'
module Digest
# A mutex for Digest().
REQUIRE_MUTEX = Mutex.new
REQUIRE_MUTEX = Thread::Mutex.new
def self.const_missing(name) # :nodoc:
case name

Просмотреть файл

@ -182,7 +182,7 @@ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__ # :nodoc:
# Debug is not available in safe mode.
class DEBUGGER__
MUTEX = Mutex.new # :nodoc:
MUTEX = Thread::Mutex.new # :nodoc:
class Context # :nodoc:
DEBUG_LAST_CMD = []

Просмотреть файл

@ -1205,7 +1205,7 @@ module DRb
# not normally need to deal with it directly.
class DRbConn
POOL_SIZE = 16 # :nodoc:
@mutex = Mutex.new
@mutex = Thread::Mutex.new
@pool = []
def self.open(remote_uri) # :nodoc:
@ -1824,7 +1824,7 @@ module DRb
end
module_function :install_acl
@mutex = Mutex.new
@mutex = Thread::Mutex.new
def mutex # :nodoc:
@mutex
end

Просмотреть файл

@ -28,7 +28,7 @@ module DRb
@cond = new_cond
@servers = {}
@waiting = []
@queue = Queue.new
@queue = Thread::Queue.new
@thread = invoke_thread
@uri = nil
end

Просмотреть файл

@ -41,7 +41,7 @@ EOF
unless defined? BINDING_QUEUE
require "thread"
IRB.const_set(:BINDING_QUEUE, SizedQueue.new(1))
IRB.const_set(:BINDING_QUEUE, Thread::SizedQueue.new(1))
Thread.abort_on_exception = true
Thread.start do
eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__

Просмотреть файл

@ -153,7 +153,7 @@ module MonitorMixin
def initialize(monitor)
@monitor = monitor
@cond = ::ConditionVariable.new
@cond = Thread::ConditionVariable.new
end
end
@ -241,7 +241,7 @@ module MonitorMixin
def mon_initialize
@mon_owner = nil
@mon_count = 0
@mon_mutex = Mutex.new
@mon_mutex = Thread::Mutex.new
end
def mon_check_owner

Просмотреть файл

@ -102,7 +102,7 @@ module Mutex_m
private
def mu_initialize # :nodoc:
@_mutex = Mutex.new
@_mutex = Thread::Mutex.new
end
def initialize(*args) # :nodoc:

Просмотреть файл

@ -128,7 +128,7 @@ class PStore
@abort = false
@ultra_safe = false
@thread_safe = thread_safe
@lock = Mutex.new
@lock = Thread::Mutex.new
end
# Raises PStore::Error if the calling code is not in a PStore#transaction.

Просмотреть файл

@ -180,7 +180,7 @@ class Resolv
def initialize(filename = DefaultFileName)
@filename = filename
@mutex = Mutex.new
@mutex = Thread::Mutex.new
@initialized = nil
end
@ -334,7 +334,7 @@ class Resolv
# :ndots => 1)
def initialize(config_info=nil)
@mutex = Mutex.new
@mutex = Thread::Mutex.new
@config = Config.new(config_info)
@initialized = nil
end
@ -625,7 +625,7 @@ class Resolv
end
RequestID = {} # :nodoc:
RequestIDMutex = Mutex.new # :nodoc:
RequestIDMutex = Thread::Mutex.new # :nodoc:
def self.allocate_request_id(host, port) # :nodoc:
id = nil
@ -910,7 +910,7 @@ class Resolv
class Config # :nodoc:
def initialize(config_info=nil)
@mutex = Mutex.new
@mutex = Thread::Mutex.new
@config_info = config_info
@initialized = nil
@timeouts = nil

Просмотреть файл

@ -385,7 +385,7 @@ module Rinda
# TupleSpaces can be found by calling +to_a+.
def lookup_ring_any(timeout=5)
queue = Queue.new
queue = Thread::Queue.new
Thread.new do
self.lookup_ring(timeout) do |ts|

Просмотреть файл

@ -246,7 +246,7 @@ module Rinda
def initialize(place, event, tuple, expires=nil)
ary = [event, Rinda::Template.new(tuple)]
super(ary, expires)
@queue = Queue.new
@queue = Thread::Queue.new
@done = false
end

Просмотреть файл

@ -12,8 +12,6 @@
require "e2mmap"
require "thread" unless defined?(Mutex)
require "forwardable"
require "shell/error"
@ -100,7 +98,7 @@ class Shell
@debug_display_process_id = false
@debug_display_thread_id = true
@debug_output_mutex = Mutex.new
@debug_output_mutex = Thread::Mutex.new
class << Shell
extend Forwardable

Просмотреть файл

@ -18,11 +18,11 @@ class Shell
class ProcessController
@ProcessControllers = {}
@ProcessControllersMonitor = Mutex.new
@ProcessControllersCV = ConditionVariable.new
@ProcessControllersMonitor = Thread::Mutex.new
@ProcessControllersCV = Thread::ConditionVariable.new
@BlockOutputMonitor = Mutex.new
@BlockOutputCV = ConditionVariable.new
@BlockOutputMonitor = Thread::Mutex.new
@BlockOutputCV = Thread::ConditionVariable.new
class << self
extend Forwardable
@ -97,8 +97,8 @@ class Shell
@active_jobs = []
@jobs_sync = Sync.new
@job_monitor = Mutex.new
@job_condition = ConditionVariable.new
@job_monitor = Thread::Mutex.new
@job_condition = Thread::ConditionVariable.new
end
attr_reader :shell
@ -238,8 +238,8 @@ class Shell
pid = nil
pid_mutex = Mutex.new
pid_cv = ConditionVariable.new
pid_mutex = Thread::Mutex.new
pid_cv = Thread::ConditionVariable.new
Thread.start do
ProcessController.block_output_synchronize do

Просмотреть файл

@ -22,7 +22,7 @@ class Shell
@command = command
@opts = opts
@input_queue = Queue.new
@input_queue = Thread::Queue.new
@pid = nil
sh.process_controller.add_schedule(self)

Просмотреть файл

@ -133,7 +133,7 @@ module Singleton
def __init__(klass) # :nodoc:
klass.instance_eval {
@singleton__instance__ = nil
@singleton__mutex__ = Mutex.new
@singleton__mutex__ = Thread::Mutex.new
}
def klass.instance # :nodoc:
return @singleton__instance__ if @singleton__instance__

Просмотреть файл

@ -261,7 +261,7 @@ module Sync_m
@sync_ex_locker = nil
@sync_ex_count = 0
@sync_mutex = Mutex.new
@sync_mutex = Thread::Mutex.new
end
def initialize(*args)

Просмотреть файл

@ -51,7 +51,7 @@ class ThreadsWait
#
def initialize(*threads)
@threads = []
@wait_queue = Queue.new
@wait_queue = Thread::Queue.new
join_nowait(*threads) unless threads.empty?
end

Просмотреть файл

@ -91,7 +91,7 @@ class Tracer
Tracer::display_thread_id = true
Tracer::display_c_call = false
@stdout_mutex = Mutex.new
@stdout_mutex = Thread::Mutex.new
# Symbol table used for displaying trace information
EVENT_SYMBOL = {

Просмотреть файл

@ -111,7 +111,7 @@ module WEBrick
@instance_key = hexdigest(self.__id__, Time.now.to_i, Process.pid)
@opaques = {}
@last_nonce_expire = Time.now
@mutex = Mutex.new
@mutex = Thread::Mutex.new
end
##

Просмотреть файл

@ -38,7 +38,7 @@ module WEBrick
@path = path
@mtime = Time.at(0)
@digest = Hash.new
@mutex = Mutex::new
@mutex = Thread::Mutex::new
@auth_type = DigestAuth
open(@path,"a").close unless File::exist?(@path)
reload

Просмотреть файл

@ -98,7 +98,7 @@ module WEBrick
@config[:Logger] ||= Log::new
@logger = @config[:Logger]
@tokens = SizedQueue.new(@config[:MaxClients])
@tokens = Thread::SizedQueue.new(@config[:MaxClients])
@config[:MaxClients].times{ @tokens.push(nil) }
webrickv = WEBrick::VERSION

Просмотреть файл

@ -126,7 +126,7 @@ module WEBrick
##
# Mutex used to synchronize access across threads
TimeoutMutex = Mutex.new # :nodoc:
TimeoutMutex = Thread::Mutex.new # :nodoc:
##
# Registers a new timeout handler
@ -154,7 +154,7 @@ module WEBrick
TimeoutMutex.synchronize{
@timeout_info = Hash.new
}
@queue = Queue.new
@queue = Thread::Queue.new
@watcher = nil
end

Просмотреть файл

@ -1,5 +1,6 @@
class Thread
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
MUTEX_FOR_THREAD_EXCLUSIVE = Thread::Mutex.new # :nodoc:
private_constant :MUTEX_FOR_THREAD_EXCLUSIVE
# call-seq:
# Thread.exclusive { block } => obj
@ -8,7 +9,7 @@ class Thread
# value of the block. A thread executing inside the exclusive section will
# only block other threads which also use the Thread.exclusive mechanism.
def self.exclusive
warn "Thread.exclusive is deprecated, use Mutex", caller
warn "Thread.exclusive is deprecated, use Thread::Mutex", caller
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
yield
}

Просмотреть файл

@ -23,7 +23,7 @@ class Dhasen
include DRbUndumped
def initialize
@mutex = Mutex.new
@mutex = Thread::Mutex.new
end
def sparse(str, *arg)

Просмотреть файл

@ -10,7 +10,7 @@ class Logger
def initialize(fname)
@fname = fname.to_s
@fp = File.open(@fname, "a+")
@queue = Queue.new
@queue = Thread::Queue.new
@th = Thread.new { self.flush }
end

Просмотреть файл

@ -6,7 +6,7 @@
require 'thread'
require 'drb/drb'
DRb.start_service(nil, Queue.new)
DRb.start_service(nil, Thread::Queue.new)
puts DRb.uri
DRb.thread.join

Просмотреть файл

@ -18,7 +18,7 @@ module DRb
def initialize(config, drb)
@config = config
@drb = drb
@queue = Queue.new
@queue = Thread::Queue.new
end
def do_POST(req, res)
@ -46,7 +46,7 @@ module DRb
def initialize(uri, config)
@uri = uri
@config = config
@queue = Queue.new
@queue = Thread::Queue.new
setup_webrick(uri)
end
attr_reader :uri

Просмотреть файл

@ -75,7 +75,7 @@ class Seq
def initialize(v, name)
@counter = v
@mutex = Mutex.new
@mutex = Thread::Mutex.new
self.drb_name = name
end
@ -90,7 +90,7 @@ end
class Front
def initialize
seq = Seq.new(0, 'seq')
mutex = Mutex.new
mutex = Thread::Mutex.new
mutex.extend(DRbUndumped)
mutex.extend(DRbNamedObject)
mutex.drb_name = 'mutex'

Просмотреть файл

@ -8,7 +8,7 @@ srand
N=9 # number of philosophers
$forks = []
for i in 0..N-1
$forks[i] = Mutex.new
$forks[i] = Thread::Mutex.new
end
$state = "-o"*N

Просмотреть файл

@ -1008,7 +1008,7 @@ module MiniTest
@report = []
@errors = @failures = @skips = 0
@verbose = false
@mutex = defined?(Mutex) ? Mutex.new : nil
@mutex = Thread::Mutex.new
@info_signal = Signal.list['INFO']
end

Просмотреть файл

@ -5,6 +5,8 @@ require "thread"
require "test/unit"
class TestMonitor < Test::Unit::TestCase
Queue = Thread::Queue
def setup
@monitor = Monitor.new
end

Просмотреть файл

@ -3,8 +3,8 @@ require 'thread'
class LocalBarrier
def initialize(n)
@wait = Queue.new
@done = Queue.new
@wait = Thread::Queue.new
@done = Thread::Queue.new
@keeper = begin_keeper(n)
end

Просмотреть файл

@ -228,7 +228,7 @@ class TestBacktrace < Test::Unit::TestCase
def test_thread_backtrace
begin
q = Queue.new
q = Thread::Queue.new
th = Thread.new{
th_rec q
}
@ -256,7 +256,7 @@ class TestBacktrace < Test::Unit::TestCase
def test_thread_backtrace_locations_with_range
begin
q = Queue.new
q = Thread::Queue.new
th = Thread.new{
th_rec q
}

Просмотреть файл

@ -121,8 +121,8 @@ class TestFile < Test::Unit::TestCase
def test_truncate_size
Tempfile.create("test-truncate") do |f|
q1 = Queue.new
q2 = Queue.new
q1 = Thread::Queue.new
q2 = Thread::Queue.new
th = Thread.new do
data = ''

Просмотреть файл

@ -1119,7 +1119,7 @@ class TestRegexp < Test::Unit::TestCase
end
def test_once_multithread
m = Mutex.new
m = Thread::Mutex.new
pr3 = proc{|i|
/#{m.unlock; sleep 0.5; i}/o
}

Просмотреть файл

@ -96,7 +96,7 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_synchronize
m = Mutex.new
m = Thread::Mutex.new
r = 0
num_threads = 10
loop=100
@ -120,7 +120,7 @@ class TestThread < Test::Unit::TestCase
def test_mutex_synchronize_yields_no_block_params
bug8097 = '[ruby-core:53424] [Bug #8097]'
assert_empty(Mutex.new.synchronize {|*params| break params}, bug8097)
assert_empty(Thread::Mutex.new.synchronize {|*params| break params}, bug8097)
end
def test_local_barrier
@ -346,8 +346,8 @@ class TestThread < Test::Unit::TestCase
def test_report_on_exception
assert_separately([], <<~"end;") #do
q1 = Queue.new
q2 = Queue.new
q1 = Thread::Queue.new
q2 = Thread::Queue.new
assert_equal(false, Thread.report_on_exception,
"global flags is false by default")
@ -513,7 +513,7 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_deadlock
m = Mutex.new
m = Thread::Mutex.new
m.synchronize do
assert_raise(ThreadError) do
m.synchronize do
@ -524,7 +524,7 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_interrupt
m = Mutex.new
m = Thread::Mutex.new
m.lock
t = Thread.new do
m.lock
@ -536,7 +536,7 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_illegal_unlock
m = Mutex.new
m = Thread::Mutex.new
m.lock
assert_raise(ThreadError) do
Thread.new do
@ -546,8 +546,8 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_fifo_like_lock
m1 = Mutex.new
m2 = Mutex.new
m1 = Thread::Mutex.new
m2 = Thread::Mutex.new
m1.lock
m2.lock
m1.unlock
@ -555,7 +555,7 @@ class TestThread < Test::Unit::TestCase
assert_equal(false, m1.locked?)
assert_equal(false, m2.locked?)
m3 = Mutex.new
m3 = Thread::Mutex.new
m1.lock
m2.lock
m3.lock
@ -568,7 +568,7 @@ class TestThread < Test::Unit::TestCase
end
def test_mutex_trylock
m = Mutex.new
m = Thread::Mutex.new
assert_equal(true, m.try_lock)
assert_equal(false, m.try_lock, '[ruby-core:20943]')
@ -753,7 +753,7 @@ class TestThread < Test::Unit::TestCase
end
def test_handle_interrupted?
q = Queue.new
q = Thread::Queue.new
Thread.handle_interrupt(RuntimeError => :never){
done = false
th = Thread.new{
@ -902,7 +902,7 @@ _eom
def test_main_thread_status_at_exit
assert_in_out_err([], <<-'INPUT', ["false false aborting"], [])
require 'thread'
q = Queue.new
q = Thread::Queue.new
Thread.new(Thread.current) {|mth|
begin
q.push nil
@ -969,7 +969,7 @@ q.pop
end
def test_mutex_owned
mutex = Mutex.new
mutex = Thread::Mutex.new
assert_equal(mutex.owned?, false)
mutex.synchronize {
@ -981,7 +981,7 @@ q.pop
def test_mutex_owned2
begin
mutex = Mutex.new
mutex = Thread::Mutex.new
th = Thread.new {
# lock forever
mutex.lock
@ -998,7 +998,7 @@ q.pop
def test_mutex_unlock_on_trap
assert_in_out_err([], <<-INPUT, %w(locked unlocked false), [])
m = Mutex.new
m = Thread::Mutex.new
trapped = false
Signal.trap("INT") { |signo|
@ -1063,7 +1063,7 @@ q.pop
def test_blocking_mutex_unlocked_on_fork
bug8433 = '[ruby-core:55102] [Bug #8433]'
mutex = Mutex.new
mutex = Thread::Mutex.new
flag = false
mutex.lock

Просмотреть файл

@ -411,7 +411,7 @@ class TestTime < Test::Unit::TestCase
end
def test_time_interval
m = Mutex.new.lock
m = Thread::Mutex.new.lock
assert_nothing_raised {
Timeout.timeout(10) {
m.sleep(0)

Просмотреть файл

@ -142,7 +142,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
r1, w = IO.pipe
s1, s2 = UNIXSocket.pair
s1.nonblock = s2.nonblock = true
lock = Mutex.new
lock = Thread::Mutex.new
nr = 0
x = 2
y = 1000

Просмотреть файл

@ -8,7 +8,7 @@ class TestMutexM < Test::Unit::TestCase
o = Object.new
o.instance_variable_set(:@foo, nil)
o.extend(Mutex_m)
c = ConditionVariable.new
c = Thread::ConditionVariable.new
t = Thread.start {
o.synchronize do
until foo = o.instance_variable_get(:@foo)

Просмотреть файл

@ -246,8 +246,8 @@ puts Tempfile.new('foo').path
def test_concurrency
threads = []
tempfiles = []
lock = Mutex.new
cond = ConditionVariable.new
lock = Thread::Mutex.new
cond = Thread::ConditionVariable.new
start = false
4.times do

Просмотреть файл

@ -5,7 +5,7 @@ require 'thread'
class TestTimeout < Test::Unit::TestCase
def test_queue
q = Queue.new
q = Thread::Queue.new
assert_raise(Timeout::Error, "[ruby-dev:32935]") {
Timeout.timeout(0.01) { q.pop }
}

Просмотреть файл

@ -4,6 +4,9 @@ require 'thread'
require 'tmpdir'
class TestConditionVariable < Test::Unit::TestCase
ConditionVariable = Thread::ConditionVariable
Mutex = Thread::Mutex
def test_initialized
assert_raise(TypeError) {
ConditionVariable.allocate.wait(nil)

Просмотреть файл

@ -5,6 +5,9 @@ require 'tmpdir'
require 'timeout'
class TestQueue < Test::Unit::TestCase
Queue = Thread::Queue
SizedQueue = Thread::SizedQueue
def test_queue_initialized
assert_raise(TypeError) {
Queue.allocate.push(nil)