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

Prefer qualified names under Thread

This commit is contained in:
Nobuyoshi Nakada 2021-06-28 23:01:53 +09:00
parent 983c9ad3f1
commit 9eae8cdefb
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
23 changed files with 181 additions and 179 deletions

View file

@ -1,9 +1,9 @@
# two threads, two mutex, two condvar ping-pong
require 'thread'
m1 = Mutex.new
m2 = Mutex.new
cv1 = ConditionVariable.new
cv2 = ConditionVariable.new
m1 = Thread::Mutex.new
m2 = Thread::Mutex.new
cv1 = Thread::ConditionVariable.new
cv2 = Thread::ConditionVariable.new
max = 100000
i = 0
wait = nil

View file

@ -1,16 +1,16 @@
# many threads, one mutex, many condvars
require 'thread'
m = Mutex.new
cv1 = ConditionVariable.new
cv2 = ConditionVariable.new
m = Thread::Mutex.new
cv1 = Thread::ConditionVariable.new
cv2 = Thread::ConditionVariable.new
max = 1000
n = 100
waiting = 0
scvs = []
waiters = n.times.map do |i|
start_cv = ConditionVariable.new
start_cv = Thread::ConditionVariable.new
scvs << start_cv
start_mtx = Mutex.new
start_mtx = Thread::Mutex.new
start_mtx.synchronize do
th = Thread.new(start_mtx, start_cv) do |sm, scv|
m.synchronize do

View file

@ -384,7 +384,7 @@ tests = [
[ 'opt_empty_p', %q{ ''.empty? }, ],
[ 'opt_empty_p', %q{ [].empty? }, ],
[ 'opt_empty_p', %q{ {}.empty? }, ],
[ 'opt_empty_p', %q{ Queue.new.empty? }, ],
[ 'opt_empty_p', %q{ Thread::Queue.new.empty? }, ],
[ 'opt_succ', %q{ 1.succ == 2 }, ],
if defined? $FIXNUM_MAX then

View file

@ -533,7 +533,7 @@ assert_equal '[RuntimeError, "ok", true]', %q{
# threads in a ractor will killed
assert_equal '{:ok=>3}', %q{
Ractor.new Ractor.current do |main|
q = Queue.new
q = Thread::Queue.new
Thread.new do
q << true
loop{}

View file

@ -76,7 +76,7 @@
# def_delegators :@q, :clear, :first, :push, :shift, :size
# end
#
# q = Queue.new
# q = Thread::Queue.new
# q.enq 1, 2, 3, 4, 5
# q.push 6
#

View file

@ -73,32 +73,32 @@ module Mutex_m
mu_initialize
end
# See Mutex#synchronize
# See Thread::Mutex#synchronize
def mu_synchronize(&block)
@_mutex.synchronize(&block)
end
# See Mutex#locked?
# See Thread::Mutex#locked?
def mu_locked?
@_mutex.locked?
end
# See Mutex#try_lock
# See Thread::Mutex#try_lock
def mu_try_lock
@_mutex.try_lock
end
# See Mutex#lock
# See Thread::Mutex#lock
def mu_lock
@_mutex.lock
end
# See Mutex#unlock
# See Thread::Mutex#unlock
def mu_unlock
@_mutex.unlock
end
# See Mutex#sleep
# See Thread::Mutex#sleep
def sleep(timeout = nil)
@_mutex.sleep(timeout)
end

View file

@ -28,7 +28,7 @@ end
class ChatServer
def initialize
@mutex = Mutex.new
@mutex = Thread::Mutex.new
@members = {}
end

View file

@ -21,7 +21,7 @@ class Scheduler
@closed = false
@lock = Mutex.new
@lock = Thread::Mutex.new
@blocking = 0
@ready = []
@ -170,7 +170,7 @@ class Scheduler
Fiber.yield
end
# Used for Kernel#sleep and Mutex#sleep
# Used for Kernel#sleep and Thread::Mutex#sleep
def kernel_sleep(duration = nil)
# $stderr.puts [__method__, duration, Fiber.current].inspect
@ -179,7 +179,8 @@ class Scheduler
return true
end
# Used when blocking on synchronization (Mutex#lock, Queue#pop, SizedQueue#push, ...)
# Used when blocking on synchronization (Thread::Mutex#lock,
# Thread::Queue#pop, Thread::SizedQueue#push, ...)
def block(blocker, timeout = nil)
# $stderr.puts [__method__, blocker, timeout].inspect
@ -201,7 +202,8 @@ class Scheduler
end
end
# Used when synchronization wakes up a previously-blocked fiber (Mutex#unlock, Queue#push, ...).
# Used when synchronization wakes up a previously-blocked fiber
# (Thread::Mutex#unlock, Thread::Queue#push, ...).
# This might be called from another thread.
def unblock(blocker, fiber)
# $stderr.puts [__method__, blocker, fiber].inspect

View file

@ -4,7 +4,7 @@ require_relative 'scheduler'
class TestFiberMutex < Test::Unit::TestCase
def test_mutex_synchronize
mutex = Mutex.new
mutex = Thread::Mutex.new
thread = Thread.new do
scheduler = Scheduler.new
@ -23,7 +23,7 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_mutex_interleaved_locking
mutex = Mutex.new
mutex = Thread::Mutex.new
thread = Thread.new do
scheduler = Scheduler.new
@ -48,7 +48,7 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_mutex_thread
mutex = Mutex.new
mutex = Thread::Mutex.new
mutex.lock
thread = Thread.new do
@ -71,7 +71,7 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_mutex_fiber_raise
mutex = Mutex.new
mutex = Thread::Mutex.new
ran = false
main = Thread.new do
@ -103,8 +103,8 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_condition_variable
mutex = Mutex.new
condition = ConditionVariable.new
mutex = Thread::Mutex.new
condition = Thread::ConditionVariable.new
signalled = 0
@ -138,7 +138,7 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_queue
queue = Queue.new
queue = Thread::Queue.new
processed = 0
thread = Thread.new do
@ -169,7 +169,7 @@ class TestFiberMutex < Test::Unit::TestCase
end
def test_queue_pop_waits
queue = Queue.new
queue = Thread::Queue.new
running = false
thread = Thread.new do
@ -198,7 +198,7 @@ class TestFiberMutex < Test::Unit::TestCase
assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], error_pattern, success: false
require 'scheduler'
mutex = Mutex.new
mutex = Thread::Mutex.new
thread = Thread.new do
scheduler = Scheduler.new

View file

@ -19,7 +19,7 @@ class TestMonitor < Test::Unit::TestCase
def test_enter
ary = []
queue = Queue.new
queue = Thread::Queue.new
th = Thread.start {
queue.pop
@monitor.enter
@ -83,7 +83,7 @@ class TestMonitor < Test::Unit::TestCase
def test_synchronize
ary = []
queue = Queue.new
queue = Thread::Queue.new
th = Thread.start {
queue.pop
@monitor.synchronize do
@ -108,7 +108,7 @@ class TestMonitor < Test::Unit::TestCase
def test_killed_thread_in_synchronize
ary = []
queue = Queue.new
queue = Thread::Queue.new
t1 = Thread.start {
queue.pop
@monitor.synchronize {
@ -136,8 +136,8 @@ class TestMonitor < Test::Unit::TestCase
end
def test_try_enter
queue1 = Queue.new
queue2 = Queue.new
queue1 = Thread::Queue.new
queue2 = Thread::Queue.new
th = Thread.start {
queue1.deq
@monitor.enter
@ -176,8 +176,8 @@ class TestMonitor < Test::Unit::TestCase
end
def test_mon_locked_and_owned
queue1 = Queue.new
queue2 = Queue.new
queue1 = Thread::Queue.new
queue2 = Thread::Queue.new
th = Thread.start {
@monitor.enter
queue1.enq(nil)
@ -210,7 +210,7 @@ class TestMonitor < Test::Unit::TestCase
cond = @monitor.new_cond
a = "foo"
queue1 = Queue.new
queue1 = Thread::Queue.new
th = Thread.start do
queue1.deq
@monitor.synchronize do
@ -262,7 +262,7 @@ class TestMonitor < Test::Unit::TestCase
def test_timedwait
cond = @monitor.new_cond
b = "foo"
queue2 = Queue.new
queue2 = Thread::Queue.new
th = Thread.start do
queue2.deq
@monitor.synchronize do
@ -282,7 +282,7 @@ class TestMonitor < Test::Unit::TestCase
assert_join_threads([th, th2])
c = "foo"
queue3 = Queue.new
queue3 = Thread::Queue.new
th = Thread.start do
queue3.deq
@monitor.synchronize do
@ -312,7 +312,7 @@ class TestMonitor < Test::Unit::TestCase
# end
# end
# }
# queue3 = Queue.new
# queue3 = Thread::Queue.new
# Thread.start do
# queue3.pop
# @monitor.synchronize do

View file

@ -632,7 +632,7 @@ class TestBignum < Test::Unit::TestCase
time = Time.now
end_flag = false
num = (65536 ** 65536)
q = Queue.new
q = Thread::Queue.new
thread = Thread.new do
assert_raise(RuntimeError) {
q << true

View file

@ -131,7 +131,7 @@ class TestDir < Test::Unit::TestCase
def test_chdir_conflict
pwd = Dir.pwd
q = Queue.new
q = Thread::Queue.new
t = Thread.new do
q.pop
Dir.chdir(pwd) rescue $!

View file

@ -814,7 +814,7 @@ end.join
bug12741 = '[ruby-core:77222] [Bug #12741]'
x = Thread.current
q = Queue.new
q = Thread::Queue.new
y = Thread.start do
q.pop
begin

View file

@ -3736,7 +3736,7 @@ __END__
begin;
bug13158 = '[ruby-core:79262] [Bug #13158]'
closed = nil
q = Queue.new
q = Thread::Queue.new
IO.pipe do |r, w|
thread = Thread.new do
begin

View file

@ -2433,7 +2433,7 @@ EOS
rescue SystemCallError
w.syswrite("exec failed\n")
end
q = Queue.new
q = Thread::Queue.new
th1 = Thread.new { i = 0; i += 1 while q.empty?; i }
th2 = Thread.new { j = 0; j += 1 while q.empty? && Thread.pass.nil?; j }
sleep 0.5

View file

@ -1984,7 +1984,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_thread_add_trace_func
events = []
base_line = __LINE__
q = Queue.new
q = Thread::Queue.new
t = Thread.new{
Thread.current.add_trace_func proc{|ev, file, line, *args|
events << [ev, line]
@ -2010,7 +2010,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
# other thread
events = []
m2t_q = Queue.new
m2t_q = Thread::Queue.new
t = Thread.new{
Thread.current.abort_on_exception = true
@ -2320,8 +2320,8 @@ class TestSetTraceFunc < Test::Unit::TestCase
events << Thread.current
end
q1 = Queue.new
q2 = Queue.new
q1 = Thread::Queue.new
q2 = Thread::Queue.new
th = Thread.new{
q1 << :ok; q2.pop

View file

@ -496,7 +496,7 @@ class TestThread < Test::Unit::TestCase
end
assert_in_out_err([], <<-INPUT, %w(false :sig), [], :signal=>:INT, timeout: 1, timeout_error: nil)
p Thread.ignore_deadlock
q = Queue.new
q = Thread::Queue.new
trap(:INT){q.push :sig}
Thread.ignore_deadlock = true
p q.pop
@ -731,8 +731,8 @@ class TestThread < Test::Unit::TestCase
def make_handle_interrupt_test_thread1 flag
r = []
ready_q = Queue.new
done_q = Queue.new
ready_q = Thread::Queue.new
done_q = Thread::Queue.new
th = Thread.new{
begin
Thread.handle_interrupt(RuntimeError => flag){
@ -809,7 +809,7 @@ class TestThread < Test::Unit::TestCase
def test_handle_interrupt_blocking
r = nil
q = Queue.new
q = Thread::Queue.new
e = Class.new(Exception)
th_s = Thread.current
th = Thread.start {
@ -833,7 +833,7 @@ class TestThread < Test::Unit::TestCase
def test_handle_interrupt_and_io
assert_in_out_err([], <<-INPUT, %w(ok), [])
th_waiting = true
q = Queue.new
q = Thread::Queue.new
t = Thread.new {
Thread.current.report_on_exception = false
@ -1235,7 +1235,7 @@ q.pop
end if Process.respond_to?(:fork)
def test_fork_while_locked
m = Mutex.new
m = Thread::Mutex.new
thrs = []
3.times do |i|
thrs << Thread.new { m.synchronize { Process.waitpid2(fork{})[1] } }
@ -1268,7 +1268,7 @@ q.pop
def test_fork_while_mutex_locked_by_forker
skip 'needs fork' unless Process.respond_to?(:fork)
m = Mutex.new
m = Thread::Mutex.new
m.synchronize do
pid = fork do
exit!(2) unless m.locked?

View file

@ -13,8 +13,8 @@ class TestThreadConditionVariable < Test::Unit::TestCase
end
def test_condvar_signal_and_wait
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
result = []
mutex.synchronize do
t = Thread.new do
@ -35,8 +35,8 @@ class TestThreadConditionVariable < Test::Unit::TestCase
def test_condvar_wait_exception_handling
# Calling wait in the only thread running should raise a ThreadError of
# 'stopping only thread'
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
locked = false
thread = Thread.new do
@ -61,8 +61,8 @@ class TestThreadConditionVariable < Test::Unit::TestCase
def test_condvar_wait_and_broadcast
nr_threads = 3
threads = Array.new
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
result = []
nr_threads.times do |i|
@ -91,8 +91,8 @@ class TestThreadConditionVariable < Test::Unit::TestCase
def test_condvar_wait_deadlock
assert_in_out_err([], <<-INPUT, /\Afatal\nNo live threads left\. Deadlock/, [])
mutex = Mutex.new
cv = ConditionVariable.new
mutex = Thread::Mutex.new
cv = Thread::ConditionVariable.new
klass = nil
mesg = nil
@ -112,8 +112,8 @@ INPUT
def test_condvar_wait_deadlock_2
nr_threads = 3
threads = Array.new
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
nr_threads.times do |i|
if (i != 0)
@ -136,8 +136,8 @@ INPUT
end
def test_condvar_timed_wait
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
timeout = 0.3
locked = false
@ -157,15 +157,15 @@ INPUT
end
def test_condvar_nolock
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
assert_raise(ThreadError) {condvar.wait(mutex)}
end
def test_condvar_nolock_2
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
Thread.new do
assert_raise(ThreadError) {condvar.wait(mutex)}
@ -173,8 +173,8 @@ INPUT
end
def test_condvar_nolock_3
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
Thread.new do
assert_raise(ThreadError) {condvar.wait(mutex, 0.1)}
@ -182,22 +182,22 @@ INPUT
end
def test_condvar_empty_signal
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
assert_nothing_raised(Exception) { mutex.synchronize {condvar.signal} }
end
def test_condvar_empty_broadcast
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
assert_nothing_raised(Exception) { mutex.synchronize {condvar.broadcast} }
end
def test_dup
bug9440 = '[ruby-core:59961] [Bug #9440]'
condvar = ConditionVariable.new
condvar = Thread::ConditionVariable.new
assert_raise(NoMethodError, bug9440) do
condvar.dup
end
@ -207,7 +207,7 @@ INPUT
def test_dump
bug9674 = '[ruby-core:61677] [Bug #9674]'
condvar = ConditionVariable.new
condvar = Thread::ConditionVariable.new
assert_raise_with_message(TypeError, /#{ConditionVariable}/, bug9674) do
Marshal.dump(condvar)
end
@ -219,8 +219,8 @@ INPUT
end
def test_condvar_fork
mutex = Mutex.new
condvar = ConditionVariable.new
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
thrs = (1..10).map do
Thread.new { mutex.synchronize { condvar.wait(mutex) } }
end

View file

@ -66,7 +66,7 @@ class TestThreadQueue < Test::Unit::TestCase
[e, "Enumerable"],
[Struct.new(:to_a), "Array-like"],
) do |a, type|
q = Queue.new(a.new([1,2,3]))
q = Thread::Queue.new(a.new([1,2,3]))
assert_equal(3, q.size, type)
assert_not_predicate(q, :empty?, type)
assert_equal(1, q.pop, type)
@ -77,14 +77,14 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_sized_queue_initialize
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
assert_equal 1, q.max
assert_raise(ArgumentError) { SizedQueue.new(0) }
assert_raise(ArgumentError) { SizedQueue.new(-1) }
assert_raise(ArgumentError) { Thread::SizedQueue.new(0) }
assert_raise(ArgumentError) { Thread::SizedQueue.new(-1) }
end
def test_sized_queue_assign_max
q = SizedQueue.new(2)
q = Thread::SizedQueue.new(2)
assert_equal(2, q.max)
q.max = 1
assert_equal(1, q.max)
@ -104,7 +104,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_pop_interrupt
q = Queue.new
q = Thread::Queue.new
t1 = Thread.new { q.pop }
sleep 0.01 until t1.stop?
t1.kill.join
@ -112,14 +112,14 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_pop_non_block
q = Queue.new
q = Thread::Queue.new
assert_raise_with_message(ThreadError, /empty/) do
q.pop(true)
end
end
def test_sized_queue_pop_interrupt
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
t1 = Thread.new { q.pop }
sleep 0.01 until t1.stop?
t1.kill.join
@ -127,14 +127,14 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_sized_queue_pop_non_block
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
assert_raise_with_message(ThreadError, /empty/) do
q.pop(true)
end
end
def test_sized_queue_push_interrupt
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
q.push(1)
assert_raise_with_message(ThreadError, /full/) do
q.push(2, true)
@ -142,7 +142,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_sized_queue_push_non_block
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
q.push(1)
t1 = Thread.new { q.push(2) }
sleep 0.01 until t1.stop?
@ -159,7 +159,7 @@ class TestThreadQueue < Test::Unit::TestCase
assert_normal_exit(<<-"_eom", bug5343, **{:timeout => timeout, :chdir=>d})
#{total_count}.times do |i|
open("test_thr_kill_count", "w") {|f| f.puts i }
queue = Queue.new
queue = Thread::Queue.new
r, w = IO.pipe
th = Thread.start {
queue.push(nil)
@ -178,20 +178,20 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_push_return_value
q = Queue.new
q = Thread::Queue.new
retval = q.push(1)
assert_same q, retval
end
def test_queue_clear_return_value
q = Queue.new
q = Thread::Queue.new
retval = q.clear
assert_same q, retval
end
def test_sized_queue_clear
# Fill queue, then test that SizedQueue#clear wakes up all waiting threads
sq = SizedQueue.new(2)
# Fill queue, then test that Thread::SizedQueue#clear wakes up all waiting threads
sq = Thread::SizedQueue.new(2)
2.times { sq << 1 }
t1 = Thread.new do
@ -212,19 +212,19 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_sized_queue_push_return_value
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
retval = q.push(1)
assert_same q, retval
end
def test_sized_queue_clear_return_value
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
retval = q.clear
assert_same q, retval
end
def test_sized_queue_throttle
q = SizedQueue.new(1)
q = Thread::SizedQueue.new(1)
i = 0
consumer = Thread.new do
while q.pop
@ -247,7 +247,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_thread_raise
q = Queue.new
q = Thread::Queue.new
th1 = Thread.new do
begin
q.pop
@ -277,7 +277,7 @@ class TestThreadQueue < Test::Unit::TestCase
def test_dup
bug9440 = '[ruby-core:59961] [Bug #9440]'
q = Queue.new
q = Thread::Queue.new
assert_raise(NoMethodError, bug9440) do
q.dup
end
@ -287,12 +287,12 @@ class TestThreadQueue < Test::Unit::TestCase
def test_dump
bug9674 = '[ruby-core:61677] [Bug #9674]'
q = Queue.new
q = Thread::Queue.new
assert_raise_with_message(TypeError, /#{Queue}/, bug9674) do
Marshal.dump(q)
end
sq = SizedQueue.new(1)
sq = Thread::SizedQueue.new(1)
assert_raise_with_message(TypeError, /#{SizedQueue}/, bug9674) do
Marshal.dump(sq)
end
@ -304,7 +304,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_close
[->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate|
[->{Thread::Queue.new}, ->{Thread::SizedQueue.new 3}].each do |qcreate|
q = qcreate.call
assert_equal false, q.closed?
q << :something
@ -343,15 +343,15 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_close_wakeup
close_wakeup(15, 18){Queue.new}
close_wakeup(15, 18){Thread::Queue.new}
end
def test_size_queue_close_wakeup
close_wakeup(5, 8){SizedQueue.new 9}
close_wakeup(5, 8){Thread::SizedQueue.new 9}
end
def test_sized_queue_one_closed_interrupt
q = SizedQueue.new 1
q = Thread::SizedQueue.new 1
q << :one
t1 = Thread.new {
Thread.current.report_on_exception = false
@ -368,7 +368,7 @@ class TestThreadQueue < Test::Unit::TestCase
# make sure that shutdown state is handled properly by empty? for the non-blocking case
def test_empty_non_blocking
q = SizedQueue.new 3
q = Thread::SizedQueue.new 3
3.times{|i| q << i}
# these all block cos the queue is full
@ -394,13 +394,13 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_sized_queue_closed_push_non_blocking
q = SizedQueue.new 7
q = Thread::SizedQueue.new 7
q.close
assert_raise_with_message(ClosedQueueError, /queue closed/){q.push(non_block=true)}
end
def test_blocked_pushers
q = SizedQueue.new 3
q = Thread::SizedQueue.new 3
prod_threads = 6.times.map do |i|
thr = Thread.new{
Thread.current.report_on_exception = false
@ -446,9 +446,9 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_deny_pushers
[->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate|
[->{Thread::Queue.new}, ->{Thread::SizedQueue.new 3}].each do |qcreate|
q = qcreate[]
synq = Queue.new
synq = Thread::Queue.new
prod_threads = 20.times.map do |i|
Thread.new {
synq.pop
@ -466,7 +466,7 @@ class TestThreadQueue < Test::Unit::TestCase
# size should account for waiting pushers during shutdown
def sized_queue_size_close
q = SizedQueue.new 4
q = Thread::SizedQueue.new 4
4.times{|i| q << i}
Thread.new{ q << 5 }
Thread.new{ q << 6 }
@ -478,7 +478,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_blocked_pushers_empty
q = SizedQueue.new 3
q = Thread::SizedQueue.new 3
prod_threads = 6.times.map do |i|
Thread.new{
Thread.current.report_on_exception = false
@ -510,14 +510,14 @@ class TestThreadQueue < Test::Unit::TestCase
# test thread wakeup on one-element SizedQueue with close
def test_one_element_sized_queue
q = SizedQueue.new 1
q = Thread::SizedQueue.new 1
t = Thread.new{ q.pop }
q.close
assert_nil t.value
end
def test_close_twice
[->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate|
[->{Thread::Queue.new}, ->{Thread::SizedQueue.new 3}].each do |qcreate|
q = qcreate[]
q.close
assert_nothing_raised(ClosedQueueError){q.close}
@ -525,7 +525,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_queue_close_multi_multi
q = SizedQueue.new rand(800..1200)
q = Thread::SizedQueue.new rand(800..1200)
count_items = rand(3000..5000)
count_producers = rand(10..20)
@ -587,7 +587,7 @@ class TestThreadQueue < Test::Unit::TestCase
end
assert_in_out_err([], <<-INPUT, %w(INT INT exit), [])
q = Queue.new
q = Thread::Queue.new
trap(:INT){
q.push 'INT'
}
@ -604,8 +604,8 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_fork_while_queue_waiting
q = Queue.new
sq = SizedQueue.new(1)
q = Thread::Queue.new
sq = Thread::SizedQueue.new(1)
thq = Thread.new { q.pop }
thsq = Thread.new { sq.pop }
Thread.pass until thq.stop? && thsq.stop?

View file

@ -75,7 +75,7 @@ class PStoreTest < Test::Unit::TestCase
end
def test_thread_safe
q1 = Queue.new
q1 = Thread::Queue.new
assert_raise(PStore::Error) do
th = Thread.new do
@pstore.transaction do
@ -92,7 +92,7 @@ class PStoreTest < Test::Unit::TestCase
th.join
end
end
q2 = Queue.new
q2 = Thread::Queue.new
begin
pstore = PStore.new(second_file, true)
cur = Thread.current

View file

@ -75,7 +75,7 @@ class YAMLStoreTest < Test::Unit::TestCase
end
def test_thread_safe
q1 = Queue.new
q1 = Thread::Queue.new
assert_raise(PStore::Error) do
th = Thread.new do
@yaml_store.transaction do
@ -92,7 +92,7 @@ class YAMLStoreTest < Test::Unit::TestCase
th.join
end
end
q2 = Queue.new
q2 = Thread::Queue.new
begin
yaml_store = YAML::Store.new(second_file, true)
cur = Thread.current

View file

@ -3153,7 +3153,7 @@ rb_thread_s_ignore_deadlock(VALUE _)
* deadlock condition via some other means, such as a signal.
*
* Thread.ignore_deadlock = true
* queue = Queue.new
* queue = Thread::Queue.new
*
* trap(:SIGUSR1){queue.push "Received signal"}
*

View file

@ -65,14 +65,14 @@ static void rb_mutex_abandon_locking_mutex(rb_thread_t *th);
static const char* rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th, rb_fiber_t *fiber);
/*
* Document-class: Mutex
* Document-class: Thread::Mutex
*
* Mutex implements a simple semaphore that can be used to coordinate access to
* shared data from multiple concurrent threads.
* Thread::Mutex implements a simple semaphore that can be used to
* coordinate access to shared data from multiple concurrent threads.
*
* Example:
*
* semaphore = Mutex.new
* semaphore = Thread::Mutex.new
*
* a = Thread.new {
* semaphore.synchronize {
@ -164,7 +164,7 @@ mutex_alloc(VALUE klass)
/*
* call-seq:
* Mutex.new -> mutex
* Thread::Mutex.new -> mutex
*
* Creates a new Mutex
*/
@ -600,7 +600,7 @@ mutex_sleep(int argc, VALUE *argv, VALUE self)
* mutex.synchronize { ... } -> result of the block
*
* Obtains a lock, runs the block, and releases the lock when the block
* completes. See the example under +Mutex+.
* completes. See the example under Thread::Mutex.
*/
VALUE
@ -615,7 +615,7 @@ rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg)
* mutex.synchronize { ... } -> result of the block
*
* Obtains a lock, runs the block, and releases the lock when the block
* completes. See the example under +Mutex+.
* completes. See the example under Thread::Mutex.
*/
static VALUE
rb_mutex_synchronize_m(VALUE self)
@ -792,7 +792,7 @@ queue_closed_p(VALUE self)
* Document-class: ClosedQueueError
*
* The exception class which will be raised when pushing into a closed
* Queue. See Queue#close and SizedQueue#close.
* Queue. See Thread::Queue#close and Thread::SizedQueue#close.
*/
NORETURN(static void raise_closed_queue_error(VALUE self));
@ -811,19 +811,19 @@ queue_closed_result(VALUE self, struct rb_queue *q)
}
/*
* Document-class: Queue
* Document-class: Thread::Queue
*
* The Queue class implements multi-producer, multi-consumer queues.
* It is especially useful in threaded programming when information
* must be exchanged safely between multiple threads. The Queue class
* implements all the required locking semantics.
* The Thread::Queue class implements multi-producer, multi-consumer
* queues. It is especially useful in threaded programming when
* information must be exchanged safely between multiple threads. The
* Thread::Queue class implements all the required locking semantics.
*
* The class implements FIFO type of queue. In a FIFO queue, the first
* tasks added are the first retrieved.
*
* Example:
*
* queue = Queue.new
* queue = Thread::Queue.new
*
* producer = Thread.new do
* 5.times do |i|
@ -853,9 +853,9 @@ queue_closed_result(VALUE self, struct rb_queue *q)
*
* Example:
*
* q = Queue.new
* q = Queue.new([a, b, c])
* q = Queue.new(items)
* q = Thread::Queue.new
* q = Thread::Queue.new([a, b, c])
* q = Thread::Queue.new(items)
*/
static VALUE
@ -886,7 +886,7 @@ queue_do_push(VALUE self, struct rb_queue *q, VALUE obj)
}
/*
* Document-method: Queue#close
* Document-method: Thread::Queue#close
* call-seq:
* close
*
@ -909,7 +909,7 @@ queue_do_push(VALUE self, struct rb_queue *q, VALUE obj)
*
* Example:
*
* q = Queue.new
* q = Thread::Queue.new
* Thread.new{
* while e = q.deq # wait for nil to break loop
* # ...
@ -933,7 +933,7 @@ rb_queue_close(VALUE self)
}
/*
* Document-method: Queue#closed?
* Document-method: Thread::Queue#closed?
* call-seq: closed?
*
* Returns +true+ if the queue is closed.
@ -946,7 +946,7 @@ rb_queue_closed_p(VALUE self)
}
/*
* Document-method: Queue#push
* Document-method: Thread::Queue#push
* call-seq:
* push(object)
* enq(object)
@ -1049,7 +1049,7 @@ queue_pop_should_block(int argc, const VALUE *argv)
}
/*
* Document-method: Queue#pop
* Document-method: Thread::Queue#pop
* call-seq:
* pop(non_block=false)
* deq(non_block=false)
@ -1070,7 +1070,7 @@ rb_queue_pop(int argc, VALUE *argv, VALUE self)
}
/*
* Document-method: Queue#empty?
* Document-method: Thread::Queue#empty?
* call-seq: empty?
*
* Returns +true+ if the queue is empty.
@ -1083,7 +1083,7 @@ rb_queue_empty_p(VALUE self)
}
/*
* Document-method: Queue#clear
* Document-method: Thread::Queue#clear
*
* Removes all objects from the queue.
*/
@ -1098,7 +1098,7 @@ rb_queue_clear(VALUE self)
}
/*
* Document-method: Queue#length
* Document-method: Thread::Queue#length
* call-seq:
* length
* size
@ -1113,7 +1113,7 @@ rb_queue_length(VALUE self)
}
/*
* Document-method: Queue#num_waiting
* Document-method: Thread::Queue#num_waiting
*
* Returns the number of threads waiting on the queue.
*/
@ -1127,12 +1127,12 @@ rb_queue_num_waiting(VALUE self)
}
/*
* Document-class: SizedQueue
* Document-class: Thread::SizedQueue
*
* This class represents queues of specified size capacity. The push operation
* may be blocked if the capacity is full.
*
* See Queue for an example of how a SizedQueue works.
* See Thread::Queue for an example of how a Thread::SizedQueue works.
*/
/*
@ -1162,11 +1162,11 @@ rb_szqueue_initialize(VALUE self, VALUE vmax)
}
/*
* Document-method: SizedQueue#close
* Document-method: Thread::SizedQueue#close
* call-seq:
* close
*
* Similar to Queue#close.
* Similar to Thread::Queue#close.
*
* The difference is behavior with waiting enqueuing threads.
*
@ -1187,7 +1187,7 @@ rb_szqueue_close(VALUE self)
}
/*
* Document-method: SizedQueue#max
* Document-method: Thread::SizedQueue#max
*
* Returns the maximum size of the queue.
*/
@ -1199,7 +1199,7 @@ rb_szqueue_max_get(VALUE self)
}
/*
* Document-method: SizedQueue#max=
* Document-method: Thread::SizedQueue#max=
* call-seq: max=(number)
*
* Sets the maximum size of the queue to the given +number+.
@ -1235,7 +1235,7 @@ szqueue_push_should_block(int argc, const VALUE *argv)
}
/*
* Document-method: SizedQueue#push
* Document-method: Thread::SizedQueue#push
* call-seq:
* push(object, non_block=false)
* enq(object, non_block=false)
@ -1299,7 +1299,7 @@ szqueue_do_pop(VALUE self, int should_block)
}
/*
* Document-method: SizedQueue#pop
* Document-method: Thread::SizedQueue#pop
* call-seq:
* pop(non_block=false)
* deq(non_block=false)
@ -1320,7 +1320,7 @@ rb_szqueue_pop(int argc, VALUE *argv, VALUE self)
}
/*
* Document-method: SizedQueue#clear
* Document-method: Thread::SizedQueue#clear
*
* Removes all objects from the queue.
*/
@ -1336,7 +1336,7 @@ rb_szqueue_clear(VALUE self)
}
/*
* Document-method: SizedQueue#length
* Document-method: Thread::SizedQueue#length
* call-seq:
* length
* size
@ -1353,7 +1353,7 @@ rb_szqueue_length(VALUE self)
}
/*
* Document-method: SizedQueue#num_waiting
* Document-method: Thread::SizedQueue#num_waiting
*
* Returns the number of threads waiting on the queue.
*/
@ -1367,7 +1367,7 @@ rb_szqueue_num_waiting(VALUE self)
}
/*
* Document-method: SizedQueue#empty?
* Document-method: Thread::SizedQueue#empty?
* call-seq: empty?
*
* Returns +true+ if the queue is empty.
@ -1389,7 +1389,7 @@ struct rb_condvar {
};
/*
* Document-class: ConditionVariable
* Document-class: Thread::ConditionVariable
*
* ConditionVariable objects augment class Mutex. Using condition variables,
* it is possible to suspend while in the middle of a critical section until a
@ -1397,8 +1397,8 @@ struct rb_condvar {
*
* Example:
*
* mutex = Mutex.new
* resource = ConditionVariable.new
* mutex = Thread::Mutex.new
* resource = Thread::ConditionVariable.new
*
* a = Thread.new {
* mutex.synchronize {
@ -1486,7 +1486,7 @@ do_sleep(VALUE args)
}
/*
* Document-method: ConditionVariable#wait
* Document-method: Thread::ConditionVariable#wait
* call-seq: wait(mutex, timeout=nil)
*
* Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup.
@ -1517,7 +1517,7 @@ rb_condvar_wait(int argc, VALUE *argv, VALUE self)
}
/*
* Document-method: ConditionVariable#signal
* Document-method: Thread::ConditionVariable#signal
*
* Wakes up the first thread in line waiting for this lock.
*/
@ -1531,7 +1531,7 @@ rb_condvar_signal(VALUE self)
}
/*
* Document-method: ConditionVariable#broadcast
* Document-method: Thread::ConditionVariable#broadcast
*
* Wakes up all threads waiting for this lock.
*/
@ -1565,11 +1565,11 @@ static void
Init_thread_sync(void)
{
#undef rb_intern
#if 0
rb_cMutex = rb_define_class("Mutex", rb_cObject); /* teach rdoc Mutex */
rb_cConditionVariable = rb_define_class("ConditionVariable", rb_cObject); /* teach rdoc ConditionVariable */
rb_cQueue = rb_define_class("Queue", rb_cObject); /* teach rdoc Queue */
rb_cSizedQueue = rb_define_class("SizedQueue", rb_cObject); /* teach rdoc SizedQueue */
#if defined(TEACH_RDOC) && TEACH_RDOC == 42
rb_cMutex = rb_define_class_under(rb_cThread, "Mutex", rb_cObject);
rb_cConditionVariable = rb_define_class_under(rb_cThread, "ConditionVariable", rb_cObject);
rb_cQueue = rb_define_class_under(rb_cThread, "Queue", rb_cObject);
rb_cSizedQueue = rb_define_class_under(rb_cThread, "SizedQueue", rb_cObject);
#endif
#define DEFINE_CLASS(name, super) \