HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.5.9/spec/ruby/core/mutex/try_lock_spec.rb
require File.expand_path('../../../spec_helper', __FILE__)

describe "Mutex#try_lock" do
  describe "when unlocked" do
    it "returns true" do
      m = Mutex.new
      m.try_lock.should be_true
    end

    it "locks the mutex" do
      m = Mutex.new
      m.try_lock
      m.locked?.should be_true
    end
  end

  describe "when locked by the current thread" do
    it "returns false" do
      m = Mutex.new
      m.lock
      m.try_lock.should be_false
    end
  end

  describe "when locked by another thread" do
    it "returns false" do
      m = Mutex.new
      m.lock
      Thread.new { m.try_lock }.value.should be_false
    end
  end
end