Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mutex error while using EM.defer with Ruby 2.0.0
#!/bin/bash
failed=0
COUNT=25
for (( i=1; i <= $COUNT; i++ ))
do
echo "Test # $i:"
rspec ./async_spec.rb
if (($?)) ; then
failed=$((failed+1))
fi
sleep 1
done
echo
echo "total: $COUNT"
echo "failed: $failed"
require 'fiber'
require 'eventmachine'
require 'rspec'
module RSpec
module Core
class ExampleGroup
class << self
alias_method :run_alias, :run
def run(reporter)
if EM.reactor_running?
run_alias reporter
else
out = nil
EM.run do
Fiber.new {
out = run_alias reporter
EM.stop
}.resume
end
out
end
end
end
end
end
end
describe "BasicEventMachineTest with Threads" do
it "should run EventMachine gracefully and schedule callback execution in thread" do
f = Fiber.current
operation = proc { res = 1 }
operation_res = 0
callback = proc { |proc_res| operation_res = proc_res; f.resume }
EventMachine.defer operation, callback
Fiber.yield
# this code should be executed only after the thread's return
expect(operation_res).to eq(1)
end
end
@shurab

This comment has been minimized.

Copy link
Owner Author

shurab commented Nov 14, 2013

With ruby-2.0.0-p247 async_loop.sh sometime fails with error:

1 example, 0 failures/usr/local/lib/ruby/2.0.0/thread.rb:188:in synchronize': Attempt to unlock a mutex which is not locked (ThreadError) from /usr/local/lib/ruby/2.0.0/thread.rb:188:inblock in pop'
from /usr/local/lib/ruby/2.0.0/thread.rb:187:in handle_interrupt' from /usr/local/lib/ruby/2.0.0/thread.rb:187:inpop'
from /usr/local/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1036:in `block in spawn_threadpool'
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.