Solved

Singleton and Shared Object in Linux

Posted on 2006-11-08
4
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

691 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