Solved

Singleton and Shared Object in Linux

Posted on 2006-11-08
4
353 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now