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

Use qualified names

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
parent 0df79477bd
commit 4b298ad77a
50 changed files with 100 additions and 93 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -41,7 +41,7 @@ EOF
unless defined? BINDING_QUEUE unless defined? BINDING_QUEUE
require "thread" 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.abort_on_exception = true
Thread.start do Thread.start do
eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__ eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
class Thread 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: # call-seq:
# Thread.exclusive { block } => obj # Thread.exclusive { block } => obj
@ -8,7 +9,7 @@ class Thread
# value of the block. A thread executing inside the exclusive section will # value of the block. A thread executing inside the exclusive section will
# only block other threads which also use the Thread.exclusive mechanism. # only block other threads which also use the Thread.exclusive mechanism.
def self.exclusive 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{ MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
yield yield
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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