Boost logo

Boost :

From: Pavel Antokolsky aka Zigmar (zigmar_at_[hidden])
Date: 2005-05-06 09:47:34


On 5/5/05, Neal Becker <ndbecker2_at_[hidden]> wrote:
> I'm curious as to how singleton behaves with respect to shared libraries.
> Is this tested? I'd imagine the results are platform-dependent.

I've tested Singleton library for various aspects, including this. On
my test platform (windows, VC7.1) the singleton in shared libraries
(dlls) does not work as expected.

I've made the following test: I've create two shared libraries and a
test program.
The first shared library (my_manager.dll) contained the singleton class itself
The second (other_lib.dll) contained a class that uses the singleton
(from my_manager.dll)
The test program was linked with both libraries and also uses the
singleton (from my_manager.dll) and test class from other_lib.dll

The test shown that the singleton actually creates _twise_ once from
test program, and once from other_lib.dll, therefor resulting two
independent instances, instead of one instance shared for entire
process.

I was a very disappointed with those results. I liked a Singleton
library design very much, but this aspect makes it nearly useless for
my work, because our typically application are split across multiple
shared libraries, where many of the have to access some shared
resource. Our current implementation is very simplistic (GOF-style),
but it least it works across multiple shared libraries.

Hope there is a way to work around this problem.

-- 
Best regards,
Zigmar
P.S. Have anyone done such tests with *nix shared libraries? They are
very much different from windows dlls, so I'm curious how does it
behaves there...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk