Skip to content

Commit

Permalink
Enable win32 concurrent_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Sep 17, 2019
1 parent 0ccc99c commit 0708f2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
40 changes: 21 additions & 19 deletions spec/std/concurrent_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,32 @@ private def raising_job : String
end

describe "concurrent" do
describe "parallel" do
it "does four things concurrently" do
a, b, c, d = parallel(1 + 2, "hello".size, [1, 2, 3, 4].size, nil)
a.should eq(3)
b.should eq(5)
c.should eq(4)
d.should be_nil
end

it "re-raises errors from Fibers as ConcurrentExecutionException" do
exception = expect_raises(ConcurrentExecutionException) do
a, b = parallel(raising_job, raising_job)
{% unless flag?(:win32) %}
describe "parallel" do
it "does four things concurrently" do
a, b, c, d = parallel(1 + 2, "hello".size, [1, 2, 3, 4].size, nil)
a.should eq(3)
b.should eq(5)
c.should eq(4)
d.should be_nil
end

exception.cause.should be_a(SomeParallelJobException)
end
it "re-raises errors from Fibers as ConcurrentExecutionException" do
exception = expect_raises(ConcurrentExecutionException) do
a, b = parallel(raising_job, raising_job)
end

it "is strict about the return value type" do
a, b = parallel(1 + 2, "hello")
exception.cause.should be_a(SomeParallelJobException)
end

typeof(a).should eq(Int32)
typeof(b).should eq(String)
it "is strict about the return value type" do
a, b = parallel(1 + 2, "hello")

typeof(a).should eq(Int32)
typeof(b).should eq(String)
end
end
end
{% end %}

describe "spawn" do
it "uses spawn macro" do
Expand Down
28 changes: 13 additions & 15 deletions src/gc/boehm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,20 @@ module GC
end

# pushes the stack of pending fibers when the GC wants to collect memory:
{% unless flag?(:win32) %}
GC.before_collect do
Fiber.unsafe_each do |fiber|
fiber.push_gc_roots unless fiber.running?
end
GC.before_collect do
Fiber.unsafe_each do |fiber|
fiber.push_gc_roots unless fiber.running?
end

{% if flag?(:preview_mt) %}
Thread.unsafe_each do |thread|
if scheduler = thread.@scheduler
fiber = scheduler.@current
GC.set_stackbottom(thread, fiber.@stack_bottom)
end
{% if flag?(:preview_mt) %}
Thread.unsafe_each do |thread|
if scheduler = thread.@scheduler
fiber = scheduler.@current
GC.set_stackbottom(thread, fiber.@stack_bottom)
end
{% end %}
end
{% end %}

GC.unlock_write
end
{% end %}
GC.unlock_write
end
end
12 changes: 5 additions & 7 deletions src/spec/example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ module Spec
ensure
Spec.run_after_each_hooks

{% unless flag?(:win32) %}
# We do this to give a chance for signals (like CTRL+C) to be handled,
# which currently are only handled when there's a fiber switch
# (IO stuff, sleep, etc.). Without it the user might wait more than needed
# after pressing CTRL+C to quit the tests.
Fiber.yield
{% end %}
# We do this to give a chance for signals (like CTRL+C) to be handled,
# which currently are only handled when there's a fiber switch
# (IO stuff, sleep, etc.). Without it the user might wait more than needed
# after pressing CTRL+C to quit the tests.
Fiber.yield
end
end
end
Expand Down

0 comments on commit 0708f2c

Please sign in to comment.