Opened 15 years ago

Closed 14 years ago

#1154 closed Bugs (fixed)

tss destruction segfaults in conjunction with dlopen/dlclose

Reported by: Zak Kipling <zak@…> Owned by: Anthony Williams
Milestone: To Be Determined Component: thread
Version: Boost 1.34.1 Severity: Regression
Keywords: Cc:

Description

The attached code (a main program that loads a "plugin" library with dlopen and calls a function therein, then unloads it with dlclose before exiting normally) works fine with Boost 1.33.1, but segfaults on exit with 1.34.1 (observed on x86_64 with Linux 2.6.20 / glibc 2.5 / gcc 4.1.2).

The segfault appears to occur because, in the new version, the boost::function objects wrapping the cleanup functions are all kept until there no longer any thread_specific_ptr objects of *any* type remaining.

Since the main program keeps a thread_specific_ptr across the dlopen/dlclose calls, and the "plugin" library created a thread_specific_ptr to a type that only exists within that library, the boost::function internals for the cleanup function on that local type are only instantiated within the library. Hence delaying its destruction until program exit (after the call to dlclose) leads to a segfault because the internals of this boost::function type have now been unloaded.

The attached Makefile should build the testcase, but you'll probably need to modify the top two lines (LDLIBS and CPPFLAGS) to point to your Boost headers and libraries.

I appreciate that this code has been reworked in order to reduce the use of (potentially limited) thread-local storage slots on the system -- is it possible to retain this while still having each instance of thread_specific_ptr manage and destroy its own cleanup function rather than deferring the destruction of all cleanup functions until program exit?

Attachments (3)

Makefile (339 bytes ) - added by Zak Kipling <zak@…> 15 years ago.
Makefile to build test case
main.cc (523 bytes ) - added by Zak Kipling <zak@…> 15 years ago.
Source to main program of test case
plugin.cc (178 bytes ) - added by Zak Kipling <zak@…> 15 years ago.
Source to plugin library of test case

Download all attachments as: .zip

Change History (4)

by Zak Kipling <zak@…>, 15 years ago

Attachment: Makefile added

Makefile to build test case

by Zak Kipling <zak@…>, 15 years ago

Attachment: main.cc added

Source to main program of test case

by Zak Kipling <zak@…>, 15 years ago

Attachment: plugin.cc added

Source to plugin library of test case

comment:1 by Anthony Williams, 14 years ago

Resolution: fixed
Status: newclosed

Unable to reproduce with current trunk. I believe the cause was fixed in 1.35.

Note: See TracTickets for help on using tickets.