Solved

Singleton and Shared Object in Linux

Posted on 2006-11-08
4
360 Views
Last Modified: 2010-04-01
Hi,

I have a singleton object that contains a std::map object and this singleton needs to be used by a main progamming thread and it's sub thread.
Everything is fine until i dymanically load a .so file and try to use the singleton. In the main thread and it's sub thread the singleton shows all the same values in the map object but when i look once inside the .so file the map is completely blank.

Can anyone help?
0
Comment
Question by:cossy74
  • 3
4 Comments
 
LVL 17

Expert Comment

by:rstaveley
ID: 17904894
It looks to me like you have two copies of the singleton: one linked into main and the other in the .so.

You can avoid this by passing a reference to the map to the .so functions and thus avoid "linking" the map into the .so.

Otherwise, you need to export global symbols (using -Wl,-E if GCC is your compiler) and dlopen your .so, if that's what you are doing, with RTLD_GLOBAL.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 17904906
Actually...

> RTLD_GLOBAL

...shouldn't be relevant for your problem. That's just for exporting RTTI. See if the -E flag sorts you out on its own.
0
 

Author Comment

by:cossy74
ID: 18135592
rstaveley: Thanks for he comment but i am having trouble testing your solution as i am using autoreconf and ./configure to build the project. DO you know how to set the -E flag using them?
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 500 total points
ID: 18137393
I'm not experienced with autoconf.

Since it is a test, I'd run ./configure as usual and then manually edit the Makefile. Does the generated Makefile make sense?

Otherwise, you could take a look through the ./configure script and see if it has something like --with-compiler-option, but I'd be surprised if it has anything useful.

If you type...

  ./configure --help

...do you get the options?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question