[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Singleton and Shared Object in Linux

Posted on 2006-11-08
4
Medium Priority
?
380 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 2000 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

834 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