$27 GRAYBYTE WORDPRESS FILE MANAGER $37

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 104.21.43.35 | ADMIN IP 216.73.216.23
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/ruby20/lib64/ruby/2.0.0/

HOME
Current File : /opt/alt/ruby20/lib64/ruby/2.0.0//thread.rb
#
#               thread.rb - thread support classes
#                       by Yukihiro Matsumoto <[email protected]>
#
# Copyright (C) 2001  Yukihiro Matsumoto
# Copyright (C) 2000  Network Applied Communication Laboratory, Inc.
# Copyright (C) 2000  Information-technology Promotion Agency, Japan
#

unless defined? Thread
  raise "Thread not available for this ruby interpreter"
end

unless defined? ThreadError
  class ThreadError < StandardError
  end
end

if $DEBUG
  Thread.abort_on_exception = true
end

#
# ConditionVariable objects augment class Mutex. Using condition variables,
# it is possible to suspend while in the middle of a critical section until a
# resource becomes available.
#
# Example:
#
#   require 'thread'
#
#   mutex = Mutex.new
#   resource = ConditionVariable.new
#
#   a = Thread.new {
#     mutex.synchronize {
#       # Thread 'a' now needs the resource
#       resource.wait(mutex)
#       # 'a' can now have the resource
#     }
#   }
#
#   b = Thread.new {
#     mutex.synchronize {
#       # Thread 'b' has finished using the resource
#       resource.signal
#     }
#   }
#
class ConditionVariable
  #
  # Creates a new ConditionVariable
  #
  def initialize
    @waiters = {}
    @waiters_mutex = Mutex.new
  end

  #
  # Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup.
  #
  # If +timeout+ is given, this method returns after +timeout+ seconds passed,
  # even if no other thread doesn't signal.
  #
  def wait(mutex, timeout=nil)
    Thread.handle_interrupt(StandardError => :never) do
      begin
        Thread.handle_interrupt(StandardError => :on_blocking) do
          @waiters_mutex.synchronize do
            @waiters[Thread.current] = true
          end
          mutex.sleep timeout
        end
      ensure
        @waiters_mutex.synchronize do
          @waiters.delete(Thread.current)
        end
      end
    end
    self
  end

  #
  # Wakes up the first thread in line waiting for this lock.
  #
  def signal
    Thread.handle_interrupt(StandardError => :on_blocking) do
      begin
        t, _ = @waiters_mutex.synchronize { @waiters.shift }
        t.run if t
      rescue ThreadError
        retry # t was already dead?
      end
    end
    self
  end

  #
  # Wakes up all threads waiting for this lock.
  #
  def broadcast
    Thread.handle_interrupt(StandardError => :on_blocking) do
      threads = nil
      @waiters_mutex.synchronize do
        threads = @waiters.keys
        @waiters.clear
      end
      for t in threads
        begin
          t.run
        rescue ThreadError
        end
      end
    end
    self
  end
end

#
# This class provides a way to synchronize communication between threads.
#
# Example:
#
#   require 'thread'
#
#   queue = Queue.new
#
#   producer = Thread.new do
#     5.times do |i|
#       sleep rand(i) # simulate expense
#       queue << i
#       puts "#{i} produced"
#     end
#   end
#
#   consumer = Thread.new do
#     5.times do |i|
#       value = queue.pop
#       sleep rand(i/2) # simulate expense
#       puts "consumed #{value}"
#     end
#   end
#
#   consumer.join
#
class Queue
  #
  # Creates a new queue.
  #
  def initialize
    @que = []
    @que.taint          # enable tainted communication
    @num_waiting = 0
    self.taint
    @mutex = Mutex.new
    @cond = ConditionVariable.new
  end

  #
  # Pushes +obj+ to the queue.
  #
  def push(obj)
    Thread.handle_interrupt(StandardError => :on_blocking) do
      @mutex.synchronize do
        @que.push obj
        @cond.signal
      end
    end
  end

  #
  # Alias of push
  #
  alias << push

  #
  # Alias of push
  #
  alias enq push

  #
  # Retrieves data from the queue.  If the queue is empty, the calling thread is
  # suspended until data is pushed onto the queue.  If +non_block+ is true, the
  # thread isn't suspended, and an exception is raised.
  #
  def pop(non_block=false)
    Thread.handle_interrupt(StandardError => :on_blocking) do
      @mutex.synchronize do
        while true
          if @que.empty?
            if non_block
              raise ThreadError, "queue empty"
            else
              begin
                @num_waiting += 1
                @cond.wait @mutex
              ensure
                @num_waiting -= 1
              end
            end
          else
            return @que.shift
          end
        end
      end
    end
  end

  #
  # Alias of pop
  #
  alias shift pop

  #
  # Alias of pop
  #
  alias deq pop

  #
  # Returns +true+ if the queue is empty.
  #
  def empty?
    @que.empty?
  end

  #
  # Removes all objects from the queue.
  #
  def clear
    @que.clear
  end

  #
  # Returns the length of the queue.
  #
  def length
    @que.length
  end

  #
  # Alias of length.
  #
  alias size length

  #
  # Returns the number of threads waiting on the queue.
  #
  def num_waiting
    @num_waiting
  end
end

#
# 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.
#
class SizedQueue < Queue
  #
  # Creates a fixed-length queue with a maximum size of +max+.
  #
  def initialize(max)
    raise ArgumentError, "queue size must be positive" unless max > 0
    @max = max
    @enque_cond = ConditionVariable.new
    @num_enqueue_waiting = 0
    super()
  end

  #
  # Returns the maximum size of the queue.
  #
  def max
    @max
  end

  #
  # Sets the maximum size of the queue.
  #
  def max=(max)
    raise ArgumentError, "queue size must be positive" unless max > 0

    @mutex.synchronize do
      if max <= @max
        @max = max
      else
        diff = max - @max
        @max = max
        diff.times do
          @enque_cond.signal
        end
      end
    end
    max
  end

  #
  # Pushes +obj+ to the queue.  If there is no space left in the queue, waits
  # until space becomes available.
  #
  def push(obj)
    Thread.handle_interrupt(RuntimeError => :on_blocking) do
      @mutex.synchronize do
        while true
          break if @que.length < @max
          @num_enqueue_waiting += 1
          begin
            @enque_cond.wait @mutex
          ensure
            @num_enqueue_waiting -= 1
          end
        end

        @que.push obj
        @cond.signal
      end
    end
  end

  #
  # Removes all objects from the queue.
  #
  def clear
    super
    @mutex.synchronize do
      @max.times do
        @enque_cond.signal
      end
    end
  end

  #
  # Alias of push
  #
  alias << push

  #
  # Alias of push
  #
  alias enq push

  #
  # Retrieves data from the queue and runs a waiting thread, if any.
  #
  def pop(*args)
    retval = super
    @mutex.synchronize do
      if @que.length < @max
        @enque_cond.signal
      end
    end
    retval
  end

  #
  # Alias of pop
  #
  alias shift pop

  #
  # Alias of pop
  #
  alias deq pop

  #
  # Returns the number of threads waiting on the queue.
  #
  def num_waiting
    @num_waiting + @num_enqueue_waiting
  end
end

# Documentation comments:
#  - How do you make RDoc inherit documentation from superclass?


Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
3 Mar 2024 10.43 PM
root / root
0755
cgi
--
3 Mar 2024 10.43 PM
root / linksafe
0755
date
--
3 Mar 2024 10.43 PM
root / linksafe
0755
digest
--
3 Mar 2024 10.43 PM
root / linksafe
0755
dl
--
3 Mar 2024 10.43 PM
root / linksafe
0755
drb
--
3 Mar 2024 10.43 PM
root / linksafe
0755
fiddle
--
3 Mar 2024 10.43 PM
root / linksafe
0755
irb
--
3 Mar 2024 10.43 PM
root / linksafe
0755
json
--
3 Mar 2024 10.43 PM
root / linksafe
0755
matrix
--
3 Mar 2024 10.43 PM
root / linksafe
0755
net
--
3 Mar 2024 10.43 PM
root / linksafe
0755
openssl
--
3 Mar 2024 10.43 PM
root / linksafe
0755
optparse
--
3 Mar 2024 10.43 PM
root / linksafe
0755
psych
--
3 Mar 2024 10.43 PM
root / linksafe
0755
racc
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rake
--
3 Mar 2024 10.53 PM
root / linksafe
0755
rbconfig
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rdoc
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rexml
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rinda
--
3 Mar 2024 10.43 PM
root / linksafe
0755
ripper
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rss
--
3 Mar 2024 10.43 PM
root / linksafe
0755
rubygems
--
3 Mar 2024 10.43 PM
root / linksafe
0755
shell
--
3 Mar 2024 10.43 PM
root / linksafe
0755
syslog
--
3 Mar 2024 10.43 PM
root / root
0755
test
--
3 Mar 2024 10.43 PM
root / linksafe
0755
uri
--
3 Mar 2024 10.43 PM
root / linksafe
0755
webrick
--
3 Mar 2024 10.43 PM
root / linksafe
0755
x86_64-linux
--
3 Mar 2024 10.43 PM
root / root
0755
xmlrpc
--
3 Mar 2024 10.43 PM
root / linksafe
0755
yaml
--
3 Mar 2024 10.43 PM
root / linksafe
0755
English.rb
6.443 KB
4 Feb 2013 2.50 AM
root / linksafe
0644
abbrev.rb
3.313 KB
24 Feb 2013 5.06 AM
root / linksafe
0644
base64.rb
2.631 KB
2 Oct 2009 10.45 AM
root / linksafe
0644
benchmark.rb
17.939 KB
18 Jul 2012 3.56 AM
root / linksafe
0644
cgi.rb
9.391 KB
30 Nov 2012 5.06 AM
root / linksafe
0644
cmath.rb
7.223 KB
23 Jul 2011 12.14 PM
root / linksafe
0644
complex.rb
0.371 KB
16 Aug 2009 3.34 PM
root / linksafe
0644
csv.rb
81.322 KB
17 Sep 2014 5.56 AM
root / linksafe
0644
date.rb
0.924 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
debug.rb
28.898 KB
2 Feb 2013 5.04 AM
root / linksafe
0644
delegate.rb
9.783 KB
30 Apr 2014 7.45 AM
root / linksafe
0644
digest.rb
2.244 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
dl.rb
0.273 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
drb.rb
0.019 KB
2 Oct 2009 10.45 AM
root / linksafe
0644
e2mmap.rb
3.805 KB
19 May 2011 12.07 AM
root / linksafe
0644
erb.rb
26.084 KB
3 Sep 2014 4.42 AM
root / linksafe
0644
expect.rb
2.144 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
fiddle.rb
1.252 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
fileutils.rb
46.353 KB
16 Oct 2014 7.23 AM
root / linksafe
0644
find.rb
2.082 KB
20 Sep 2012 7.14 AM
root / linksafe
0644
forwardable.rb
7.562 KB
4 Jan 2013 2.52 AM
root / linksafe
0644
getoptlong.rb
15.381 KB
24 Dec 2013 3.46 PM
root / linksafe
0644
gserver.rb
8.856 KB
7 Jul 2014 3.55 AM
root / linksafe
0644
ipaddr.rb
26.17 KB
23 Feb 2013 4.03 AM
root / linksafe
0644
irb.rb
20.029 KB
5 Feb 2013 3.57 PM
root / linksafe
0644
json.rb
1.737 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
kconv.rb
5.737 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
logger.rb
20.96 KB
13 Jul 2013 3.16 PM
root / linksafe
0644
mathn.rb
6.524 KB
26 Aug 2011 10.22 PM
root / linksafe
0644
matrix.rb
45.019 KB
5 Feb 2013 5.43 AM
root / linksafe
0644
mkmf.rb
78.186 KB
26 Jul 2023 2.06 PM
root / linksafe
0644
monitor.rb
6.935 KB
16 Nov 2012 4.55 PM
root / linksafe
0644
mutex_m.rb
2.002 KB
24 Feb 2013 4.49 AM
root / linksafe
0644
observer.rb
5.705 KB
21 Aug 2012 1.03 PM
root / linksafe
0644
open-uri.rb
23.656 KB
16 Feb 2014 5.02 PM
root / linksafe
0644
open3.rb
21.172 KB
13 Jan 2013 4.40 AM
root / linksafe
0644
openssl.rb
0.516 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
optparse.rb
51.267 KB
19 Feb 2014 4.38 PM
root / linksafe
0644
ostruct.rb
7.636 KB
28 Oct 2012 9.20 PM
root / linksafe
0644
pathname.rb
15.297 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
pp.rb
13.136 KB
15 Aug 2012 11.50 AM
root / linksafe
0644
prettyprint.rb
9.628 KB
2 Aug 2011 3.25 PM
root / linksafe
0644
prime.rb
13.978 KB
13 Jan 2013 5.07 AM
root / linksafe
0644
profile.rb
0.2 KB
2 Oct 2009 10.45 AM
root / linksafe
0644
profiler.rb
4.287 KB
3 Feb 2013 12.38 AM
root / linksafe
0644
pstore.rb
14.849 KB
11 Nov 2012 4.23 AM
root / linksafe
0644
psych.rb
9.896 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
rake.rb
2.069 KB
29 Nov 2012 7.16 PM
root / linksafe
0644
rational.rb
0.301 KB
24 Sep 2009 12.42 AM
root / linksafe
0644
rdoc.rb
4.877 KB
19 Feb 2013 5.06 AM
root / linksafe
0644
resolv-replace.rb
1.732 KB
3 Apr 2013 5.27 PM
root / linksafe
0644
resolv.rb
61.449 KB
1 Jun 2015 3.13 PM
root / linksafe
0644
ripper.rb
2.525 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
rss.rb
2.841 KB
11 May 2011 10.22 AM
root / linksafe
0644
rubygems.rb
27.534 KB
26 Jul 2023 2.06 PM
root / linksafe
0644
scanf.rb
23.517 KB
5 Nov 2011 7.37 AM
root / linksafe
0644
securerandom.rb
8.563 KB
13 Sep 2012 1.01 PM
root / linksafe
0644
set.rb
17.316 KB
24 Nov 2012 6.51 PM
root / linksafe
0644
shell.rb
10.3 KB
5 Dec 2012 2.55 AM
root / linksafe
0644
shellwords.rb
5.94 KB
9 Nov 2012 6.28 AM
root / linksafe
0644
singleton.rb
4.018 KB
18 May 2011 2.09 PM
root / linksafe
0644
socket.rb
25.758 KB
26 Jul 2023 2.09 PM
root / linksafe
0644
sync.rb
7.256 KB
23 Dec 2012 10.18 AM
root / linksafe
0644
tempfile.rb
10.153 KB
9 Oct 2013 4.11 PM
root / linksafe
0644
thread.rb
6.944 KB
9 Feb 2014 4.07 PM
root / linksafe
0644
thwait.rb
3.376 KB
29 Jun 2011 3.09 AM
root / linksafe
0644
time.rb
21.091 KB
9 Oct 2013 3.07 PM
root / linksafe
0644
timeout.rb
3.163 KB
14 Apr 2013 3.20 PM
root / linksafe
0644
tmpdir.rb
4.148 KB
12 Dec 2012 12.40 PM
root / linksafe
0644
tracer.rb
6.537 KB
4 Feb 2013 5.59 PM
root / linksafe
0644
tsort.rb
6.795 KB
6 Mar 2009 4.23 AM
root / linksafe
0644
ubygems.rb
0.262 KB
2 Oct 2009 10.45 AM
root / linksafe
0644
un.rb
8.337 KB
3 Aug 2012 8.23 AM
root / linksafe
0644
uri.rb
3.07 KB
13 May 2011 8.03 PM
root / linksafe
0644
weakref.rb
3.229 KB
2 Dec 2012 7.57 AM
root / linksafe
0644
webrick.rb
6.695 KB
7 Nov 2012 6.49 AM
root / linksafe
0644
xmlrpc.rb
8.493 KB
13 Sep 2012 2.24 AM
root / linksafe
0644
yaml.rb
2.303 KB
19 May 2013 7.01 PM
root / linksafe
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF