Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Singleton and Shared Object in Linux

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

650 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