Prevent to initialize MonitorMixin twice
Some libraries or tests unfortunately do something like:
require 'monitor' class Foo include MonitorMixin def initialize(*args) super() mon_initialize end end
This unfortunately ends up initializing the monitor twice.
If the two monitor initializations are done concurrently,
we can end up with two threads entering the same Monitor concurrently,
as they can acquire two different Mutex instances.
I'd proposed to raise an exception if
@mon_mutex is already set, like
raise "already initialized" if @mon_mutex.
This doesn't fully solve the problem if allocate is used and #initialize is called concurrently, but then I think it's the user's fault.
I originally found this problem while running Rails tests, but I can't find the exact source file anymore causing this.
Still, I think it's better to check here.