Hi all,
The following code demonstrates thread_specific_ptr problem
while loading/unloading a shared library. Apparently some resource is not
cleanned up. Can somebody comment on this?
Thanks,
Arkadiy
lib.cpp:
-------
#include <string>
#include <boost/thread.hpp>
boost::thread_specific_ptr < std::string >
tls_with_mmap;
main.cpp:
----------
#include <stdint.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <stdio.h>
int main( int argc, const char* argv[])
{
if( argc < 3 )
{
printf("usage %s <dlname> <repeat count>\n", argv[0]);
return 1;
}
const char* dlname = argv[1];
uint16_t iters = atoi(argv[2]);
for( uint16_t i = 0; i < iters; ++i )
{
printf("attempt %02d\n", i);
void* handle =
::dlopen(dlname, RTLD_NOW );
if( handle )
::dlclose(handle);
else
{
printf("dlopen failed\n");
break;
}
}
return 0;
}
build.sh:
--------
BOOST_VER=38
CCFLAGS="-Wcomment -Wformat -Wmissing-braces
-Wparentheses -Wreturn-type -Wsign-compare -Wstrict-aliasing -Wswitch
-Wtrigraphs -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value
-Wunused-variable -Wextra -g -O0 -fno-inline -fexceptions -ftemplate-depth-128
-Wnon-virtual-dtor -I/usr/include/nptl
-I/builder/3rdParty/boost/v${BOOST_VER}.0/include -D__NO_INLINE__=1 -D_DEBUG
-DDEBUG"
g++ -x c++ -m32 ${CCFLAGS} -fPIC -pipe -o
"lib.o" -c "lib.cpp"
g++ -m32 -o boost_thread_test.so -shared
-Wl,-Bsymbolic -Wl,-h -Wl,boost_thread_test.so -Wl,--no-undefined
-Wl,--start-group lib.o
/builder/3rdParty/boost/v${BOOST_VER}.0/lib32/gcc-3.4.6/libboost_thread-mt-d.a
/usr/lib/libpthread.so -lstdc++ -lc -lm -Wl,--end-group
g++ -x c++ -m32 ${CCFLAGS} -fPIC -pipe -o
"main.o" -c "main.cpp"
g++ -m32 -o boost_thread_test.exe
-Wl,--start-group main.o /usr/lib/libpthread.so /usr/lib/libdl.so
-lstdc++ -lc -lm -Wl,--end-group
Linux version:
--------------
Red Hat Enterprise Linux ES release 4 (Nahant Update 4)
Invocation:
-----------
> ./boost_thread_test.exe ./boost_thread_test.so 600
…
attempt 509
attempt 510
attempt 511
boost_thread_test.exe: libs/thread/src/pthread/thread.cpp:102:
void boost::detail::<unnamed>::create_current_thread_tls_key(): Assertion
`!pthread_key_create(¤t_thread_tls_key,&tls_destructor)' failed.
Aborted