Boost logo

Boost :

From: David Brownell (david_brownell_at_[hidden])
Date: 2003-03-26 15:06:24

> The user can just call the method for every thread which uses
> in a static library implementation. If a library ( LIB ) function uses
> Boost.Threads internally, then it is up to the library function
> to document this and iteratively define a function which can be called
> calls the Boost.Threads function before the thread ends or, if the library
> function itself controls the ending of the thread, it must do it itself.

As I have researched this topic, it has become quite clear that I am nowhere
near an expert in this area, so forgive me if these questions are naive or
have been hashed over before.

Are these statements accurate: When a thread is created within a static lib,
there is no way to find out when the thread has completed. In a DLL,
DllMain is called when the thread is complete. This is important because
TLS data must be destroyed when the thread is complete. In the current
version of boost (1.30), TLS is a feature of the thread library, but not
required. In future versions of boost, threads themselves will rely on TLS
internally, so TLS is no longer a feature, but required.

If a user must link with a static thread lib, a workaround would be for them
to notify the thread library that the thread is about to complete, and any
associated TLS data can be destroyed. This is not an optimum solution, as
it places the onus on the user.

Some questions: In the current thread library, can the associated TLS data
be deleted before the thread is complete? In the next version of the
library, can the associated TLS data be deleted before the thread is

Would it be possible to add a level of indirection in the thread functor in
static lib builds? For example, in a DLL build, the following happens (this
is very loose, but should convey my meaning):

--Thread Created (thread lib)
       -- User's thread functor (user code)
--Thread Destroyed (thread lib)

In a static lib build:

-- Thread Created (thread lib)
       -- Internal thread functor (thread lib)
              -- User's thread functor (user code)
              -- Destroy TLS (thread lib)
-- Thread Destroyed (thread lib)

This would free the user from calling a destroy function at the end of the
thread proc, but would enable static builds (if the above assumptions are

David Brownell

Boost list run by bdawes at, gregod at, cpdaniel at, john at