summaryrefslogtreecommitdiff
path: root/prelude.rb
blob: 2b371e71340d6140efbf89bc461d251deb1a1663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Thread
  MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:

  # call-seq:
  #    Thread.exclusive { block }   => obj
  #
  # Wraps a block in Thread.critical, restoring the original value
  # upon exit from the critical section, and returns the value of the
  # block.
  def self.exclusive
    MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
      yield
    }
  end
end