Boost logo

Boost Users :

Subject: [Boost-users] boost::thread_specific_ptr
From: jono (jp_at_[hidden])
Date: 2009-05-25 00:35:32


hi all,

i'm using thread_specific_ptr (boost 1.33.1, sorry) in a plugin architecture, where the tls
identifies a singleton object of type Context (initialized using DCLP).

boost::thread_specific_ptr<Context> Context::instance_;

i also have a set of shared libraries and a main executable linked against a static library defining
the Context class.

this all works fine so long as the libraries are loaded and the threads created in that order,
however, if a library is loaded after thread is started, then the thread_specific_ptr in that thread
appears to be reset to null, without calling cleanup().

if i use the debugger to inspect the singleton ptr before and after loading the second module, it
is, before:

$1 = {<boost::noncopyable_::noncopyable> = {<No data fields>}, m_tss =
{<boost::noncopyable_::noncopyable> = {<No data fields>}, m_slot = 8}}

..and after:

$2 = {<boost::noncopyable_::noncopyable> = {<No data fields>}, m_tss =
{<boost::noncopyable_::noncopyable> = {<No data fields>}, m_slot = 1}}

is this correct behaviour for thread_specific_ptr? is there a way i can obtain a handle for the
first Context object before it is destroyed?

here's some info about my system.

$ cat /proc/cpuinfo
...
AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
...

$ uname -a
Linux lumpen 2.6.19 #2 SMP Fri Jan 12 17:58:33 NZDT 2007 x86_64 x86_64 x86_64 GNU/Linux

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)

any help would be appreciated.

cheers,
Jono


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net