Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f172bed30b31
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 54544961d044
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 17, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a37094f View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5454496 View commit details
Showing with 17 additions and 2 deletions.
  1. +7 −2 kernel/bootstrap/thread.rb
  2. +10 −0 spec/ruby/core/thread/join_spec.rb
9 changes: 7 additions & 2 deletions kernel/bootstrap/thread.rb
Original file line number Diff line number Diff line change
@@ -219,6 +219,11 @@ def add_to_group(group)
end

def join_inner(timeout = undefined)
if undefined.equal?(timeout) || nil.equal?(timeout)
timeout = nil
else
timeout = Rubinius::Type.coerce_to_float(timeout)
end
result = nil
Rubinius.lock(self)
begin
@@ -227,14 +232,14 @@ def join_inner(timeout = undefined)
@joins << jc
Rubinius.unlock(self)
begin
if undefined.equal? timeout
if !timeout
while true
res = jc.receive
# receive returns false if it was a spurious wakeup
break if res != false
end
else
duration = timeout.to_f
duration = timeout
while true
start = Time.now.to_f
res = jc.receive_timeout duration
10 changes: 10 additions & 0 deletions spec/ruby/core/thread/join_spec.rb
Original file line number Diff line number Diff line change
@@ -13,6 +13,16 @@
t.join(0).should equal(t)
end

it "coerces timeout to a Float if it is not nil" do
t = Thread.new {}
t.join
t.join(0).should equal(t)
t.join(0.0).should equal(t)
t.join(nil).should equal(t)
lambda { t.join(:foo) }.should raise_error TypeError
lambda { t.join("bar") }.should raise_error TypeError
end

it "returns nil if it is not finished when given a timeout" do
c = Channel.new
t = Thread.new { c.receive }