perplexes / m2r

Mongrel2 Connection Adapter - Ruby Encrusted Steel-Reinforced Fist
MIT License
90 stars 11 forks source link

Create zmq_context in a threadsafe way #37

Closed paneq closed 12 years ago

paneq commented 12 years ago

http://www.engineyard.com/blog/2011/concurrency-in-jruby/

This is not thread safe:

module M2R
  class << self
    attr_writer :zmq_context

    def zmq_context(threads = 1)
      @zmq_context ||= ZMQ::Context.new(threads)
    end
  end
end

We should probably wrap it in Thread.exclusive