Re: getenv, putenv



On Jan 30, 8:59 pm, llothar <llot...@xxxxxx> wrote:
When I try to invoke same environment variable using another thread
within same process using getenv, I am not able to access the value of
env variable.

Can Anyone please let me know, what could be the probable reason for
this problem.

AFAIR there was some spec that said that you can't use getenv to
retrieve variables set by the same process. setenv is just there to
pass
variables to child processes.

I also run into this a few years ago and it has nothing to do with
multithreading.
If you can use setenv/getenv in the same process it is an
implementation
detail but trust it - and by the way why do you want to do it anyway.

The reason for it is as I posted as another message. Please find
details below.

We are using a multithreaded application which has a few dynamic
shared objects associated with it. We are running it on Linux
platform. Few of the classes and code part is common among main
executable and other DSOs. The DSOs have been linked using linker
option -Bsymbolic and so are able to keep their seperate objects for
common classes.

The issue we are having is we want to keep a true singleton of the
common class without disturbing current linker option. For this
purpose, we are allocating a new TLS key and putting this key into
environment, so that once initialised same object is used among all
DSOs. Based on what I read in man pages of pthread_key_create,
pthread_setspecific and pthread_getspecific, I can create a key as an
opaque object among multiple threads, but the values will still be
thread specific.

My specific questions in this scenario is:
1. Can I use TLS key-value pair common among multiple threads of an
application? If yes, can anybody please provide me any link to help me
on this?
2. Is there any other approach I can use to ensure that I have a
common object being shared among multiple threads belonging to
different DSOs, inspite of using -Bsymbolic linker option with DSOs?
3. Or is there any way to override the effect of -Bsymbolic linker
option for some specific symbols in any DSO, so as to ensure existence
of common symbols.

Any help in this regard willl be greatly appreciated.

Thanks and Regards
Bhawna
.



Relevant Pages

  • overriding effect of -Bsymbolic, can TLSkey be helpful?
    ... Few of the classes and code part is common among main ... The DSOs have been linked using linker ... opaque object among multiple threads, but the values will still be ... inspite of using -Bsymbolic linker option with DSOs? ...
    (comp.unix.programmer)
  • overriding effect of -Bsymbolic, can TLSkey be useful?
    ... Few of the classes and code part is common among main ... The DSOs have been linked using linker ... opaque object among multiple threads, but the values will still be ... inspite of using -Bsymbolic linker option with DSOs? ...
    (comp.os.linux.development.apps)
  • Re: Common code among main executable and shared objects
    ... common class without disturbing current linker option. ... a the TLS key index and instantiate pSingleton with already existing ... DSOs I chose to write it on Unix forum rather than c++. ...
    (comp.unix.programmer)
  • cannot compile on HPC SGI cluster
    ... I am attempting to compile MPI code on the High Performance Cluster, but am recieving errors that seem as if the compiler is not recognizing any of the MPI commands. ... Use linker option -v to see when and which objects, archives and dsos are loaded. ...
    (comp.parallel.mpi)
  • Common code among main executable and shared objects
    ... Few of the classes and code part is common among main ... The DSOs have been linked using linker ... The issue we are having is we want to keep a true singleton of the ... we are allocating a new TLS key and putting this key into ...
    (comp.unix.programmer)