Subject:
Re: [ruby-ffi] Load same library multiple times?
From:
Chuck Remes
Date:
11/20/10 4:01 PM
To:
ruby-ffi@googlegroups.com


On Nov 20, 2010, at 10:04 AM, Kim.Toms wrote:

> I'd like to load the same library multiple times, so that the global
> variables in my C program are complete separate.  This would allow me
> to run multiple simulations of objects that arre connected.  The
> objects are all communicating with each other, and I'd like to track
> the communication.  I've posted a simple example in the issues at
> https://github.com/ffi/ffi/issues/#issue/65

I don't think this is possible. When you load a library, it is mapped into the same address space as the interpreter (MRI, JRuby, Rubinius, etc.). If your library is using global variables in a global namespace, then it isn't re-entrant either.

I recommend modifying the library so it is re-entrant. Then you can load the library *once* but call into it from multiple threads safely.

cr